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

Revision 1329, 3.3 KB checked in by naka, 20 years ago (diff)

* empty log message *

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