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

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