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

Revision 4700, 3.4 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        if ( $arr ) {
54            $result = $this->conn->getOne($n, $arr);
55        } else {
56            $result = $this->conn->getOne($n);
57        }       
58        if ($this->conn->isError($result)){
59            $this->send_err_mail ($result ,$n);
60        }
61        $this->result = $result;
62        return $this->result;
63    }
64   
65    function getRow($n, $arr = ""){
66       
67        if ( $arr ) {
68            $result = $this->conn->getRow($n, $arr);
69        } else {
70            $result = $this->conn->getRow($n);
71        }       
72        if ($this->conn->isError($result)){
73            $this->send_err_mail ($result ,$n);
74        }
75        $this->result = $result;
76        return $this->result;
77    }
78
79    // SELECTʸ¤Î¼Â¹Ô·ë²Ì¤òÁ´¤Æ¼èÆÀ
80    function getAll($n, $arr = ""){
81        if(PEAR::isError($this->conn)) {
82            sfErrorHeader("DB¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£:" . $this->dsn);
83            return 0;
84        }
85       
86        sfprintr($n);
87       
88        if ( $arr ){
89            $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC);
90        } else {
91            $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC);
92        }
93       
94        if ($this->conn->isError($result)){
95            $this->send_err_mail ($result, $n);
96        }
97        $this->result = $result;
98       
99        return $this->result;
100    }   
101   
102    function autoExecute($table_name, $fields_values, $sql_where = null){
103   
104        if ( $sql_where ) {
105            $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where);
106        } else {
107            $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT);
108        }
109       
110        if ($this->conn->isError($result)){
111            $this->send_err_mail ($result, $n);
112        }
113        $this->result = $result;
114        return $this->result;
115    }
116   
117   
118    function prepare($n){
119        global $sql;
120        $sql = $n;     
121        $result = $this->conn->prepare($n);
122        $this->result = $result;
123        return $this->result;
124    }
125   
126    function execute($n, $obj){
127        global $sql;
128        $sql = $n;
129        $result = $this->conn->execute($n, $obj);
130        $this->result = $result;
131        return $this->result;
132    }   
133   
134    function reset(){
135        $this->conn->disconnect();
136    }
137
138    function send_err_mail( $result, $sql ){
139       
140        if ($_SERVER['HTTPS'] == "on") {
141            $url = "https://";
142        } else {
143            $url = "http://";
144        }
145        $url.= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
146       
147        $errmsg = $url."\n\n";
148        $errmsg.= $sql . "\n";
149        $errmsg.= $result->message . "\n\n";
150        $errmsg.= $result->userinfo . "\n\n";
151        print_r($errmsg);
152        /*
153        ob_start();
154        $errmsg .= ob_get_contents();
155        ob_end_clean();
156        */
157        //mb_send_mail($this->error_mail_to, $this->error_mail_title, "${errmsg}\n".date("Y/m/d H:i:s"));       
158        exit();
159    }
160}
161
162?>
Note: See TracBrowser for help on using the repository browser.