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

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