source: temp/trunk/data/class/SC_DbConn.php @ 5728

Revision 5728, 3.8 KB checked in by kakinaka, 20 years ago (diff)

blank

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2$current_dir = realpath(dirname(__FILE__));
3require_once($current_dir . "/../module/DB.php");
4
5$objDbConn = "";
6
7class SC_DbConn{
8
9    var $conn;
10    var $result;
11    var $includePath;
12    var $error_mail_to;
13    var $error_mail_title;
14    var $dsn;
15    var $err_disp = true;
16
17   
18    // ¥³¥ó¥¹¥È¥é¥¯¥¿
19    function SC_DbConn($dsn = "", $err_disp = true){
20        global $objDbConn;
21        // ´û¤ËÀܳ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¤ÏÀܳ¤·¤Ê¤¤
22        if(!isset($objDbConn->connection)) {
23            if($dsn != "") {
24                $objDbConn = DB::connect($dsn);
25                $this->dsn = $dsn;
26            } else {
27                $objDbConn = DB::connect(DEFAULT_DSN);
28                $this->dsn = DEFAULT_DSN;
29            }
30        }
31        $this->conn = $objDbConn;
32        $this->error_mail_to = DB_ERROR_MAIL_TO;
33        $this->error_mail_title = DB_ERROR_MAIL_SUBJECT;
34        $this->err_disp = $err_disp;
35    }
36   
37    // ¥¯¥¨¥ê¤Î¼Â¹Ô
38    function query($n ,$arr = "", $ignore_err = false){
39        if ( $arr ) {
40            $result = $this->conn->query($n, $arr);
41        } else {
42            $result = $this->conn->query($n);
43        }
44   
45        if ($this->conn->isError($result) && !$ignore_err){
46            $this->send_err_mail ($result, $n);
47        }
48       
49        $this->result = $result;
50        return $this->result;
51    }
52
53    // °ì·ï¤Î¤ß¼èÆÀ
54    function getOne($n, $arr = ""){
55       
56        // mysql¤Î¾ì¹ç¤Ë¤Ï¥Ó¥å¡¼É½¤òÊÑ´¹¤¹¤ë
57        if (DB_TYPE == "mysql") $n = sfChangeMySQL($n);
58       
59        if ( $arr ) {
60            $result = $this->conn->getOne($n, $arr);
61        } else {
62            $result = $this->conn->getOne($n);
63        }       
64        if ($this->conn->isError($result)){
65            $this->send_err_mail ($result ,$n);
66        }
67        $this->result = $result;
68       
69        return $this->result;
70    }
71   
72    function getRow($n, $arr = ""){
73
74        // mysql¤Î¾ì¹ç¤Ë¤Ï¥Ó¥å¡¼É½¤òÊÑ´¹¤¹¤ë
75        if (DB_TYPE == "mysql") $n = sfChangeMySQL($n);
76
77        if ( $arr ) {
78            $result = $this->conn->getRow($n, $arr);
79        } else {
80            $result = $this->conn->getRow($n);
81        }       
82        if ($this->conn->isError($result)){
83            $this->send_err_mail ($result ,$n);
84        }
85        $this->result = $result;
86        return $this->result;
87    }
88
89    // SELECTʸ¤Î¼Â¹Ô·ë²Ì¤òÁ´¤Æ¼èÆÀ
90    function getAll($n, $arr = ""){
91
92        // mysql¤Î¾ì¹ç¤Ë¤Ï¥Ó¥å¡¼É½¤òÊÑ´¹¤¹¤ë
93        if (DB_TYPE == "mysql") $n = sfChangeMySQL($n);
94       
95        if(PEAR::isError($this->conn)) {
96            sfErrorHeader("DB¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£:" . $this->dsn);
97            return 0;
98        }
99
100        if ( $arr ){
101            $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC);
102        } else {
103            $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC);
104        }
105       
106        if ($this->conn->isError($result)){
107            $this->send_err_mail ($result, $n);
108        }
109        $this->result = $result;
110       
111        return $this->result;
112    }   
113   
114    function autoExecute($table_name, $fields_values, $sql_where = null){
115   
116        if ( $sql_where ) {
117            $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where);
118        } else {
119            $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT);
120        }
121       
122        if ($this->conn->isError($result)){
123            $this->send_err_mail ($result, $n);
124        }
125        $this->result = $result;
126        return $this->result;
127    }
128   
129   
130    function prepare($n){
131        global $sql;
132        $sql = $n;     
133        $result = $this->conn->prepare($n);
134        $this->result = $result;
135        return $this->result;
136    }
137   
138    function execute($n, $obj){
139        global $sql;
140        $sql = $n;
141        $result = $this->conn->execute($n, $obj);
142        $this->result = $result;
143        return $this->result;
144    }   
145   
146    function reset(){
147        $this->conn->disconnect();
148    }
149
150    function send_err_mail( $result, $sql ){
151       
152        if ($this->err_disp) {
153            if ($_SERVER['HTTPS'] == "on") {
154                $url = "https://";
155            } else {
156                $url = "http://";
157            }
158            $url.= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
159           
160            $errmsg = $url."\n\n";
161            $errmsg.= $sql . "\n";
162            $errmsg.= $result->message . "\n\n";
163            $errmsg.= $result->userinfo . "\n\n";
164            print_r($errmsg);
165            /*
166            ob_start();
167            $errmsg .= ob_get_contents();
168            ob_end_clean();
169            */
170            //mb_send_mail($this->error_mail_to, $this->error_mail_title, "${errmsg}\n".date("Y/m/d H:i:s"));       
171            exit();
172        }
173    }
174}
175
176?>
Note: See TracBrowser for help on using the repository browser.