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

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