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

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