| 1 | <?php
|
|---|
| 2 | $DB_PHP_PATH = realpath( dirname( __FILE__) );
|
|---|
| 3 | require_once($DB_PHP_PATH."/../modules/DB.php");
|
|---|
| 4 |
|
|---|
| 5 | $objDbConn = "";
|
|---|
| 6 |
|
|---|
| 7 | class SC_DbConn{
|
|---|
| 8 |
|
|---|
| 9 | var $conn;
|
|---|
| 10 | var $result;
|
|---|
| 11 | var $includePath;
|
|---|
| 12 |
|
|---|
| 13 | var $error_mail_to;
|
|---|
| 14 | var $error_mail_title;
|
|---|
| 15 |
|
|---|
| 16 | function SC_DbConn($dsn = "", $new_con = false){
|
|---|
| 17 | global $objDbConn;
|
|---|
| 18 |
|
|---|
| 19 | // ¶¦Í¥ª¥Ö¥¸¥§¥¯¥È¤¬Àܳ¤µ¤ì¤Æ¤¤¤Ê¤¤¤«¡¢¿·¤·¤¯Àܳ¤·¤Ê¤ª¤¹¾ì¹ç
|
|---|
| 20 | if((!isset($objDbConn->connection)) || $new_con) {
|
|---|
| 21 | if($dsn != "") {
|
|---|
| 22 | $objDbConn = DB::connect($dsn);
|
|---|
| 23 | } else {
|
|---|
| 24 | $objDbConn = DB::connect(DEFAULT_DSN);
|
|---|
| 25 | }
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | // DB¤Ø¤ÎÀܳ¼ºÇÔ
|
|---|
| 29 | if(!isset($objDbConn->connection)) {
|
|---|
| 30 | print($objDbConn->message);
|
|---|
| 31 | exit;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | $this->conn = $objDbConn;
|
|---|
| 35 | $this->error_mail_to = DB_ERROR_MAIL_TO;
|
|---|
| 36 | $this->error_mail_title = DB_ERROR_MAIL_SUBJECT;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | function query($n ,$arr = ""){
|
|---|
| 40 | if ( $arr ) {
|
|---|
| 41 | $result = $this->conn->query($n, $arr);
|
|---|
| 42 | } else {
|
|---|
| 43 | $result = $this->conn->query($n);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | if ($this->conn->isError($result)){
|
|---|
| 47 | $this->send_err_mail ($result, $n);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | $this->result = $result;
|
|---|
| 51 | return $this->result;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | function getOne($n, $arr = ""){
|
|---|
| 55 |
|
|---|
| 56 | if ( $arr ) {
|
|---|
| 57 | $result = $this->conn->getOne($n, $arr);
|
|---|
| 58 | } else {
|
|---|
| 59 | $result = $this->conn->getOne($n);
|
|---|
| 60 | }
|
|---|
| 61 | if ($this->conn->isError($result)){
|
|---|
| 62 | $this->send_err_mail ($result ,$n);
|
|---|
| 63 | }
|
|---|
| 64 | $this->result = $result;
|
|---|
| 65 | return $this->result;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | function getRow($n, $arr = ""){
|
|---|
| 69 |
|
|---|
| 70 | if ( $arr ) {
|
|---|
| 71 | $result = $this->conn->getRow($n, $arr);
|
|---|
| 72 | } else {
|
|---|
| 73 | $result = $this->conn->getRow($n);
|
|---|
| 74 | }
|
|---|
| 75 | if ($this->conn->isError($result)){
|
|---|
| 76 | $this->send_err_mail ($result ,$n);
|
|---|
| 77 | }
|
|---|
| 78 | $this->result = $result;
|
|---|
| 79 | return $this->result;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | function getAll($n, $arr = ""){
|
|---|
| 83 |
|
|---|
| 84 | if ( $arr ){
|
|---|
| 85 | $result = $this->conn->getAll($n, $arr, DB_FETCHMODE_ASSOC);
|
|---|
| 86 | } else {
|
|---|
| 87 | $result = $this->conn->getAll($n, DB_FETCHMODE_ASSOC);
|
|---|
| 88 | }
|
|---|
| 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 | function autoExecute($table_name, $fields_values, $sql_where = null, $send_err = true){
|
|---|
| 98 |
|
|---|
| 99 | if ( $sql_where ) {
|
|---|
| 100 | $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_UPDATE, $sql_where);
|
|---|
| 101 | } else {
|
|---|
| 102 | $result = $this->conn->autoExecute( $table_name, $fields_values, DB_AUTOQUERY_INSERT);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | if ($this->conn->isError($result) and $send_err){
|
|---|
| 106 | $this->send_err_mail ($result, $n);
|
|---|
| 107 | }
|
|---|
| 108 | $this->result = $result;
|
|---|
| 109 | return $this->result;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | function prepare($n){
|
|---|
| 114 | global $sql;
|
|---|
| 115 | $sql = $n;
|
|---|
| 116 | $result = $this->conn->prepare($n);
|
|---|
| 117 | $this->result = $result;
|
|---|
| 118 | return $this->result;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | function execute($n, $obj){
|
|---|
| 122 | global $sql;
|
|---|
| 123 | $sql = $n;
|
|---|
| 124 | $result = $this->conn->execute($n, $obj);
|
|---|
| 125 | $this->result = $result;
|
|---|
| 126 | return $this->result;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | function reset(){
|
|---|
| 130 | $this->conn->disconnect();
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | function send_err_mail( $result, $sql ){
|
|---|
| 134 |
|
|---|
| 135 | if ($_SERVER['HTTPS'] == "on") {
|
|---|
| 136 | $url = "https://";
|
|---|
| 137 | } else {
|
|---|
| 138 | $url = "http://";
|
|---|
| 139 | }
|
|---|
| 140 | $url.= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
|---|
| 141 |
|
|---|
| 142 | $array = array_pop($result->backtrace);
|
|---|
| 143 |
|
|---|
| 144 | $errmsg = $url. " line:" . $array['line'] . "\n\n";
|
|---|
| 145 | $errmsg.= $sql . "\n";
|
|---|
| 146 | $errmsg.= $result->message . "\n\n";
|
|---|
| 147 | $errmsg.= $result->userinfo . "\n\n";
|
|---|
| 148 |
|
|---|
| 149 | ob_start();
|
|---|
| 150 | print_R($result);
|
|---|
| 151 | $errmsg .= ob_get_contents();
|
|---|
| 152 | ob_end_clean();
|
|---|
| 153 |
|
|---|
| 154 | mb_send_mail ( $this->error_mail_to, $this->error_mail_title, "${errmsg}\n".date("Y/m/d H:i:s") );
|
|---|
| 155 |
|
|---|
| 156 | exit;
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | ?> |
|---|