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
RevLine 
[1328]1<?php
[5922]2/*
[5934]3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
[5922]4 *
5 * http://www.lockon.co.jp/
6 */
7
[1328]8$current_dir = realpath(dirname(__FILE__));
[4702]9require_once($current_dir . "/../module/DB.php");
[1328]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;
[1330]20    var $dsn;
[5728]21    var $err_disp = true;
[1328]22   
23    // ¥³¥ó¥¹¥È¥é¥¯¥¿
[6266]24    function SC_DbConn($dsn = "", $err_disp = true, $new = false){
[1328]25        global $objDbConn;
[6112]26       
[6260]27        // Debug¥â¡¼¥É»ØÄê
28        $options['debug'] = PEAR_DB_DEBUG;
[6270]29        // ´û¤ËÀܳ¤µ¤ì¤Æ¤¤¤Ê¤¤¤«¡¢¿·µ¬ÀܳÍ×˾¤Î¾ì¹ç¤ÏÀܳ¤¹¤ë¡£
[6269]30        if(!isset($objDbConn->connection) || $new) {
[1328]31            if($dsn != "") {
[6112]32                $objDbConn = DB::connect($dsn, $options);
[1332]33                $this->dsn = $dsn;
[1328]34            } else {
[6352]35                if(defined('DEFAULT_DSN')) {
36                    $objDbConn = DB::connect(DEFAULT_DSN, $options);
37                    $this->dsn = DEFAULT_DSN;
38                } else {
39                    return;
40                }
[1328]41            }
42        }
43        $this->conn = $objDbConn;
44        $this->error_mail_to = DB_ERROR_MAIL_TO;
45        $this->error_mail_title = DB_ERROR_MAIL_SUBJECT;
[5728]46        $this->err_disp = $err_disp;
[1328]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       
[4709]68        // mysql¤Î¾ì¹ç¤Ë¤Ï¥Ó¥å¡¼É½¤òÊÑ´¹¤¹¤ë
[4761]69        if (DB_TYPE == "mysql") $n = sfChangeMySQL($n);
[4709]70       
[1328]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;
[4776]80       
[1328]81        return $this->result;
82    }
83   
84    function getRow($n, $arr = ""){
[4715]85
86        // mysql¤Î¾ì¹ç¤Ë¤Ï¥Ó¥å¡¼É½¤òÊÑ´¹¤¹¤ë
[4761]87        if (DB_TYPE == "mysql") $n = sfChangeMySQL($n);
[4715]88
[1328]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 = ""){
[4715]103
104        // mysql¤Î¾ì¹ç¤Ë¤Ï¥Ó¥å¡¼É½¤òÊÑ´¹¤¹¤ë
[4761]105        if (DB_TYPE == "mysql") $n = sfChangeMySQL($n);
[4715]106       
[1329]107        if(PEAR::isError($this->conn)) {
[1333]108            sfErrorHeader("DB¤Ø¤ÎÀܳ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£:" . $this->dsn);
[1329]109            return 0;
[4700]110        }
[4715]111
[1328]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       
[5728]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);
[6004]177
[5728]178            exit();
[1328]179        }
180    }
181}
182
183?>
Note: See TracBrowser for help on using the repository browser.