diff options
Diffstat (limited to 'phpBB/includes/db/msaccess.php')
| -rw-r--r-- | phpBB/includes/db/msaccess.php | 140 |
1 files changed, 82 insertions, 58 deletions
diff --git a/phpBB/includes/db/msaccess.php b/phpBB/includes/db/msaccess.php index d3eff04c4c..3e38cff7b0 100644 --- a/phpBB/includes/db/msaccess.php +++ b/phpBB/includes/db/msaccess.php @@ -41,10 +41,7 @@ class sql_db var $num_queries = 0; - // - // Constructor - // - function sql_db($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) + function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $persistency = true) { $this->persistency = $persistency; $this->server = $sqlserver; @@ -52,10 +49,21 @@ class sql_db $this->password = $sqlpassword; $this->dbname = $database; - $this->db_connect_id = ($this->persistency) ? odbc_pconnect($this->server, $this->user, $this->password) : odbc_connect($this->server, $this->user, $this->password); + $this->db_connect_id = ($this->persistency) ? @odbc_pconnect($this->server, $this->user, $this->password) : @odbc_connect($this->server, $this->user, $this->password); + + return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); + } + + function sql_return_on_error($fail = false) + { + $this->return_on_error = $fail; + } - return ( $this->db_connect_id ) ? $this->db_connect_id : false; + function sql_num_queries() + { + return $this->num_queries; } + // // Other base methods // @@ -63,12 +71,12 @@ class sql_db { if($this->db_connect_id) { - if( $this->in_transaction ) + if($this->in_transaction) { @odbc_commit($this->db_connect_id); } - if( count($this->result_rowset) ) + if(count($this->result_rowset)) { unset($this->result_rowset); unset($this->field_names); @@ -90,13 +98,13 @@ class sql_db // function sql_query($query = "", $transaction = FALSE) { - if( $query != "" ) + if($query != "") { $this->num_queries++; - if( $transaction == BEGIN_TRANSACTION && !$this->in_transaction ) + if($transaction == BEGIN_TRANSACTION && !$this->in_transaction) { - if( !odbc_autocommit($this->db_connect_id, false) ) + if(!odbc_autocommit($this->db_connect_id, false)) { return false; } @@ -105,23 +113,23 @@ class sql_db $query = str_replace("LOWER(", "LCASE(", $query); - if( preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits) ) + if(preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?$/s", $query, $limits)) { $query = $limits[1]; - if( !empty($limits[2]) ) + if(!empty($limits[2])) { - $row_offset = ( $limits[4] ) ? $limits[3] : ""; - $num_rows = ( $limits[4] ) ? $limits[4] : $limits[3]; + $row_offset = ($limits[4]) ? $limits[3] : ""; + $num_rows = ($limits[4]) ? $limits[4] : $limits[3]; - $query = "TOP " . ( $row_offset + $num_rows ) . $query; + $query = "TOP " . ($row_offset + $num_rows) . $query; } $this->result = odbc_exec($this->db_connect_id, "SELECT $query"); - if( $this->result ) + if($this->result) { - if( empty($this->field_names[$this->result]) ) + if(empty($this->field_names[$this->result])) { for($i = 1; $i < odbc_num_fields($this->result) + 1; $i++) { @@ -133,11 +141,11 @@ class sql_db $this->current_row[$this->result] = 0; $this->result_rowset[$this->result] = array(); - $row_outer = ( isset($row_offset) ) ? $row_offset + 1 : 1; - $row_outer_max = ( isset($num_rows) ) ? $row_offset + $num_rows + 1 : 1E9; + $row_outer = (isset($row_offset)) ? $row_offset + 1 : 1; + $row_outer_max = (isset($num_rows)) ? $row_offset + $num_rows + 1 : 1E9; $row_inner = 0; - while( odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max ) + while(odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max) { for($j = 0; $j < count($this->field_names[$this->result]); $j++) { @@ -154,16 +162,16 @@ class sql_db } } - else if( eregi("^INSERT ", $query) ) + else if(eregi("^INSERT ", $query)) { $this->result = odbc_exec($this->db_connect_id, $query); - if( $this->result ) + if($this->result) { $result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY"); - if( $result_id ) + if($result_id) { - if( odbc_fetch_row($result_id) ) + if(odbc_fetch_row($result_id)) { $this->next_id[$this->db_connect_id] = odbc_result($result_id, 1); $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result); @@ -175,15 +183,15 @@ class sql_db { $this->result = odbc_exec($this->db_connect_id, $query); - if( $this->result ) + if($this->result) { $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result); } } - if( !$this->result ) + if(!$this->result) { - if( $this->in_transaction ) + if($this->in_transaction) { odbc_rollback($this->db_connect_id); odbc_autocommit($this->db_connect_id, true); @@ -193,11 +201,11 @@ class sql_db return false; } - if( $transaction == END_TRANSACTION && $this->in_transaction ) + if($transaction == END_TRANSACTION && $this->in_transaction) { $this->in_transaction = FALSE; - if ( !@odbc_commit($this->db_connect_id) ) + if (!@odbc_commit($this->db_connect_id)) { odbc_rollback($this->db_connect_id); odbc_autocommit($this->db_connect_id, true); @@ -210,11 +218,11 @@ class sql_db } else { - if( $transaction == END_TRANSACTION && $this->in_transaction ) + if($transaction == END_TRANSACTION && $this->in_transaction) { $this->in_transaction = FALSE; - if ( !@odbc_commit($this->db_connect_id) ) + if (!@odbc_commit($this->db_connect_id)) { odbc_rollback($this->db_connect_id); odbc_autocommit($this->db_connect_id, true); @@ -232,54 +240,54 @@ class sql_db // function sql_numrows($query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - return ( $query_id ) ? $this->num_rows[$query_id] : false; + return ($query_id) ? $this->num_rows[$query_id] : false; } function sql_numfields($query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - return ( $query_id ) ? count($this->field_names[$query_id]) : false; + return ($query_id) ? count($this->field_names[$query_id]) : false; } function sql_fieldname($offset, $query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - return ( $query_id ) ? $this->field_names[$query_id][$offset] : false; + return ($query_id) ? $this->field_names[$query_id][$offset] : false; } function sql_fieldtype($offset, $query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - return ( $query_id ) ? $this->field_types[$query_id][$offset] : false; + return ($query_id) ? $this->field_types[$query_id][$offset] : false; } function sql_fetchrow($query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - if( $query_id ) + if($query_id) { - return ( $this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false; + return ($this->num_rows[$query_id] && $this->current_row[$query_id] < $this->num_rows[$query_id]) ? $this->result_rowset[$query_id][$this->current_row[$query_id]++] : false; } else { @@ -289,14 +297,14 @@ class sql_db function sql_fetchrowset($query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - if( $query_id ) + if($query_id) { - return ( $this->num_rows[$query_id] ) ? $this->result_rowset[$query_id] : false; + return ($this->num_rows[$query_id]) ? $this->result_rowset[$query_id] : false; } else { @@ -306,14 +314,14 @@ class sql_db function sql_fetchfield($field, $row = -1, $query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - if( $query_id ) + if($query_id) { - if( $row < $this->num_rows[$query_id] ) + if($row < $this->num_rows[$query_id]) { $getrow = ($row == -1) ? $this->current_row[$query_id] - 1 : $row; @@ -332,12 +340,12 @@ class sql_db function sql_rowseek($offset, $query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } - if( $query_id ) + if($query_id) { $this->current_row[$query_id] = $offset - 1; return true; @@ -350,17 +358,17 @@ class sql_db function sql_nextid() { - return ( $this->next_id[$this->db_connect_id] ) ? $this->next_id[$this->db_connect_id] : false; + return ($this->next_id[$this->db_connect_id]) ? $this->next_id[$this->db_connect_id] : false; } function sql_affectedrows() { - return ( $this->affected_rows[$this->db_connect_id] ) ? $this->affected_rows[$this->db_connect_id] : false; + return ($this->affected_rows[$this->db_connect_id]) ? $this->affected_rows[$this->db_connect_id] : false; } function sql_freeresult($query_id = 0) { - if( !$query_id ) + if(!$query_id) { $query_id = $this->result; } @@ -374,12 +382,28 @@ class sql_db return true; } - function sql_error() + function sql_error($sql = '') { - $error['code'] = "";//odbc_error($this->db_connect_id); - $error['message'] = "Error";//odbc_errormsg($this->db_connect_id); + if (!$this->return_on_error) + { + if ($this->transaction) + { + $this->sql_transaction('rollback'); + } + + $this_page = (!empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']; + $this_page .= '&' . ((!empty($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']); + + $message = '<u>SQL ERROR</u> [ ' . SQL_LAYER . ' ]<br /><br />' . @odbc_errormsg() . '<br /><br /><u>CALLING PAGE</u><br /><br />' . htmlspecialchars($this_page) . (($sql != '') ? '<br /><br /><u>SQL</u><br /><br />' . $sql : '') . '<br />'; + trigger_error($message, E_USER_ERROR); + } + + $result = array( + 'message' => @odbc_errormsg(), + 'code' => @odbc_error() + ); - return $error; + return $result; } } // class sql_db |
