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

Revision 3523, 3.4 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    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        if ( $arr ){
87            $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC);
88        } else {
89            $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC);
90        }
91       
92        if ($this->conn->isError($result)){
93            $this->send_err_mail ($result, $n);
94        }
95        $this->result = $result;
96       
97        return $this->result;
98    }   
99   
100    function autoExecute($table_name, $fields_values, $sql_where = null){
101   
102        if ( $sql_where ) {
103            $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where);
104        } else {
105            $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT);
106        }
107       
108        if ($this->conn->isError($result)){
109            $this->send_err_mail ($result, $n);
110        }
111        $this->result = $result;
112        return $this->result;
113    }
114   
115   
116    function prepare($n){
117        global $sql;
118        $sql = $n;     
119        $result = $this->conn->prepare($n);
120        $this->result = $result;
121        return $this->result;
122    }
123   
124    function execute($n, $obj){
125        global $sql;
126        $sql = $n;
127        $result = $this->conn->execute($n, $obj);
128        $this->result = $result;
129        return $this->result;
130    }   
131   
132    function reset(){
133        $this->conn->disconnect();
134    }
135
136    function send_err_mail( $result, $sql ){
137       
138        if ($_SERVER['HTTPS'] == "on") {
139            $url = "https://";
140        } else {
141            $url = "http://";
142        }
143        $url.= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
144       
145        $errmsg = $url."\n\n";
146        $errmsg.= $sql . "\n";
147        $errmsg.= $result->message . "\n\n";
148        $errmsg.= $result->userinfo . "\n\n";
149        print_r($errmsg);
150        print_R($result);
151
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.