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

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