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

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