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

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