|
From: FlorinCB <ory...@us...> - 2008-12-31 02:06:08
|
Update of /cvsroot/mxbb/phpbb2mxp/includes/db In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv12742/includes/db Added Files: dbal.php firebird.php index.htm mssql.php mssql_odbc.php mysql.php mysql4.php mysqli.php oracle.php postgres.php sqlite.php Log Message: upgrade to 2.0.24-beta1 --- NEW FILE: mysqli.php --- <?php /** * * @package DBal * @version $Id: mysqli.php,v 1.1 2008/12/31 01:44:18 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_mysqli')) { define('SQL_LAYER', 'mysqli'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** * @package DBal * MySQLi Database Abstraction Layer * mysqli-extension has to be compiled with: * MySQL 4.1+ or MySQL 5.0+ */ class dbal_mysqli extends dbal { var $multi_insert = true; /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false , $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver; $this->dbname = $database; $port = (!$port) ? NULL : $port; // Persistant connections not supported by the mysqli extension? $this->db_connect_id = @mysqli_connect($this->server, $this->user, $sqlpassword, $this->dbname, $port); if ($this->db_connect_id && $this->dbname != '') { // mysqli only supported by phpBB3 //if (UTF_STATUS === 'phpbb3') //{ @mysqli_query($this->db_connect_id, "SET NAMES 'utf8'"); // enforce strict mode on databases that support it //} if (mysqli_get_server_version($this->db_connect_id) >= 50002) { $result = @mysqli_query($this->db_connect_id, 'SELECT @@session.sql_mode AS sql_mode'); $row = @mysqli_fetch_assoc($result); @mysqli_free_result($result); $modes = array_map('trim', explode(',', $row['sql_mode'])); // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES if (!in_array('TRADITIONAL', $modes)) { if (!in_array('STRICT_ALL_TABLES', $modes)) { $modes[] = 'STRICT_ALL_TABLES'; } if (!in_array('STRICT_TRANS_TABLES', $modes)) { $modes[] = 'STRICT_TRANS_TABLES'; } } $mode = implode(',', $modes); @mysqli_query($this->db_connect_id, "SET SESSION sql_mode='{$mode}'"); } return $this->db_connect_id; } return $this->sql_error(''); } /** * Version information about used database */ function sql_server_info() { return 'MySQL(i) ' . @mysqli_get_server_info($this->db_connect_id); } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @mysqli_autocommit($this->db_connect_id, false); $this->transaction = true; break; case 'commit': $result = @mysqli_commit($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); $this->transaction = false; if (!$result) { @mysqli_rollback($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); } break; case 'rollback': $result = @mysqli_rollback($this->db_connect_id); @mysqli_autocommit($this->db_connect_id, true); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->query_result = false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @mysqli_query($this->db_connect_id, $query)) === false) { $this->sql_error($query); } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } } else if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { // MySQL 4.1+ no longer supports -1 in limit queries $total = '18446744073709551615'; } $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysqli_num_rows($query_id) : false; } /** * Return number of affected rows */ function sql_affectedrows() { return ($this->db_connect_id) ? @mysqli_affected_rows($this->db_connect_id) : false; } /** * Fetch current row */ function sql_fetchrow($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysqli_fetch_assoc($query_id) : false; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum !== false) { $this->sql_rowseek($rownum, $query_id); } $row = $this->sql_fetchrow($query_id); return isset($row[$field]) ? $row[$field] : false; } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysqli_data_seek($query_id, $rownum) : false; } /** * Get last inserted id after insert statement */ function sql_nextid() { return ($this->db_connect_id) ? @mysqli_insert_id($this->db_connect_id) : false; } /** * Free sql result */ function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } // Make sure it is not a cached query if (is_object($this->query_result)) { return @mysqli_free_result($query_id); } return false; } /** * Build LIKE expression * @access private */ function _sql_like_expression($expression) { return $expression; } /** * Build db-specific query data * @access private */ function _sql_custom_build($stage, $data) { switch ($stage) { case 'FROM': $data = '(' . $data . ')'; break; } return $data; } /** * Escape string used in sql query */ function sql_escape($msg) { return @mysqli_real_escape_string($this->db_connect_id, $msg); } /** * return sql error array * @private */ function _sql_error() { return array( 'message' => @mysqli_error($this->db_connect_id), 'code' => @mysqli_errno($this->db_connect_id) ); } /** * Close sql connection * @private */ function _sql_close() { return @mysqli_close($this->db_connect_id); } /** * Build db-specific report * @private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': $explain_query = $query; if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } if (preg_match('/^SELECT/', $explain_query)) { $html_table = false; if ($result = @mysqli_query($this->db_connect_id, "EXPLAIN $explain_query")) { while ($row = @mysqli_fetch_assoc($result)) { $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); } } @mysqli_free_result($result); if ($html_table) { $this->html_hold .= '</table>'; } } break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @mysqli_query($this->db_connect_id, $query); while ($void = @mysqli_fetch_assoc($result)) { // Take the time spent on parsing rows into account } @mysqli_free_result($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } } // if ... define // Connect to DB $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { mx_message_die(CRITICAL_ERROR, "Could not connect to the database"); } ?> --- NEW FILE: sqlite.php --- <?php /** * * @package DBal * @version $Id: sqlite.php,v 1.1 2008/12/31 01:44:18 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_sqlite')) { define('SQL_LAYER', 'sqlite'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** * @package DBal * Sqlite Database Abstraction Layer */ class dbal_sqlite extends dbal { /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; $error = ''; $this->db_connect_id = ($this->persistency) ? @sqlite_popen($this->server, 0666, $error) : @sqlite_open($this->server, 0666, $error);; if ($this->db_connect_id) { @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id); } return ($this->db_connect_id) ? true : array('message' => $error); } /** * Version information about used database */ function sql_server_info() { return 'SQLite ' . @sqlite_libversion(); } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @sqlite_query('BEGIN', $this->db_connect_id); $this->transaction = true; break; case 'commit': $result = @sqlite_query('COMMIT', $this->db_connect_id); $this->transaction = false; if (!$result) { @sqlite_query('ROLLBACK', $this->db_connect_id); } break; case 'rollback': $result = @sqlite_query('ROLLBACK', $this->db_connect_id); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $mx_cache; $query = preg_replace('#FROM \(([^)]*)\)(,|[\n\r\t ]+(?:WHERE|LEFT JOIN)) #', 'FROM \1\2 ', $query); // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->query_result = ($cache_ttl && method_exists($mx_cache, 'sql_load')) ? $mx_cache->sql_load($query) : false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @sqlite_query($query, $this->db_connect_id)) === false) { $this->sql_error($query); } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } if ($cache_ttl && method_exists($mx_cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $mx_cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } else if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { $total = -1; } $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @sqlite_num_rows($query_id) : false; } /** * Return number of affected rows */ function sql_affectedrows() { return ($this->db_connect_id) ? @sqlite_changes($this->db_connect_id) : false; } /** * Fetch current row */ function sql_fetchrow($query_id = false) { global $mx_cache; if (!$query_id) { $query_id = $this->query_result; } if (isset($mx_cache->sql_rowset[$query_id])) { return $mx_cache->sql_fetchrow($query_id); } return ($query_id) ? @sqlite_fetch_array($query_id, SQLITE_ASSOC) : false; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum === false) { return @sqlite_column($query_id, $field); } else { @sqlite_seek($query_id, $rownum); return @sqlite_column($query_id, $field); } } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @sqlite_seek($query_id, $rownum) : false; } /** * Get last inserted id after insert statement */ function sql_nextid() { return ($this->db_connect_id) ? @sqlite_last_insert_rowid($this->db_connect_id) : false; } /** * Free sql result */ function sql_freeresult($query_id = false) { return true; } /** * Escape string used in sql query */ function sql_escape($msg) { return @sqlite_escape_string($msg); } /** * Build db-specific query data * @access private */ function _sql_custom_build($stage, $data) { return $data; } /** * return sql error array * @private */ function _sql_error() { return array( 'message' => @sqlite_error_string(@sqlite_last_error($this->db_connect_id)), 'code' => @sqlite_last_error($this->db_connect_id) ); } /** * Close sql connection * @private */ function _sql_close() { return @sqlite_close($this->db_connect_id); } /** * Build db-specific report * @private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @sqlite_query($query, $this->db_connect_id); while ($void = @sqlite_fetch_array($result, SQLITE_ASSOC)) { // Take the time spent on parsing rows into account } $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } } // if ... define // Connect to DB $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { mx_message_die(CRITICAL_ERROR, "Could not connect to the database"); } ?> --- NEW FILE: postgres.php --- <?php /** * * @package DBal * @version $Id: postgres.php,v 1.1 2008/12/31 01:44:18 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_postgres')) { define('SQL_LAYER', 'postgres'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** * @package DBal * PostgreSQL Database Abstraction Layer * Minimum Requirement is Version 7.3+ */ class dbal_postgres extends dbal { var $last_query_text = ''; var $pgsql_version; /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $connect_string = ''; if ($sqluser) { $connect_string .= "user=$sqluser "; } if ($sqlpassword) { $connect_string .= "password=$sqlpassword "; } if ($sqlserver) { if (strpos($sqlserver, ':') !== false) { list($sqlserver, $port) = explode(':', $sqlserver); } if ($sqlserver !== 'localhost') { $connect_string .= "host=$sqlserver "; } if ($port) { $connect_string .= "port=$port "; } } $schema = ''; if ($database) { $this->dbname = $database; if (strpos($database, '.') !== false) { list($database, $schema) = explode('.', $database); } $connect_string .= "dbname=$database"; } $this->persistency = $persistency; $this->db_connect_id = ($this->persistency) ? @pg_pconnect($connect_string, $new_link) : @pg_connect($connect_string, $new_link); if ($this->db_connect_id) { // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ if (version_compare(PHP_VERSION, '5.0.0', '>=')) { $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); } else { $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION()'); $row = @pg_fetch_assoc($query_id, null); @pg_free_result($query_id); if (!empty($row['version'])) { $this->pgsql_version = substr($row['version'], 10); } } if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8' && $this->pgsql_version[2] >= '2') { $this->multi_insert = true; } if ($schema !== '') { @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); } return $this->db_connect_id; } return $this->sql_error(''); } /** * Version information about used database */ function sql_server_info() { return 'PostgreSQL ' . $this->pgsql_version; } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @pg_query($this->db_connect_id, 'BEGIN'); $this->transaction = true; break; case 'commit': $result = @pg_query($this->db_connect_id, 'COMMIT'); $this->transaction = false; if (!$result) { @pg_query($this->db_connect_id, 'ROLLBACK'); } break; case 'rollback': $result = @pg_query($this->db_connect_id, 'ROLLBACK'); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $mx_cache; if (strpos($query, 'SELECT') === 0 && strpos($query, 'FROM (') !== false) { $query = preg_replace('#FROM \(([^)]+)\)\s#', 'FROM \1 ', $query); } // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->last_query_text = $query; $this->query_result = ($cache_ttl && method_exists($mx_cache, 'sql_load')) ? $mx_cache->sql_load($query) : false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @pg_exec($this->db_connect_id, $query)) === false) { $this->sql_error($query); } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } if ($cache_ttl && method_exists($mx_cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $mx_cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } else if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { $total = -1; } $query .= "\n LIMIT $total OFFSET $offset"; return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @pg_num_rows($query_id) : false; } /** * Return number of affected rows */ function sql_affectedrows() { return ($this->query_result) ? @pg_cmdtuples($this->query_result) : false; } /** * Fetch current row */ function sql_fetchrow($query_id = false) { global $mx_cache; if (!$query_id) { $query_id = $this->query_result; } if (isset($mx_cache->sql_rowset[$query_id])) { return $mx_cache->sql_fetchrow($query_id); } return ($query_id) ? @pg_fetch_assoc($query_id, NULL) : false; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum !== false) { $this->sql_rowseek($rownum, $query_id); } $row = $this->sql_fetchrow($query_id); return isset($row[$field]) ? $row[$field] : false; } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @pg_result_seek($query_id, $rownum) : false; } /** * Get last inserted id after insert statement */ function sql_nextid() { $query_id = $this->query_result; if ($query_id && $this->last_query_text != '') { if (preg_match("/^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)/is", $this->last_query_text, $tablename)) { $query = "SELECT currval('" . $tablename[1] . "_id_seq') AS last_value"; $temp_q_id = @pg_query($this->db_connect_id, $query); if (!$temp_q_id) { return false; } $temp_result = @pg_fetch_assoc($temp_q_id, NULL); @pg_free_result($query_id); return ($temp_result) ? $temp_result['last_value'] : false; } } return false; } /** * Free sql result */ function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); return @pg_free_result($query_id); } } /** * Escape string used in sql query */ function sql_escape($msg) { // Do not use for bytea values return @pg_escape_string($msg); } /** * Build LIKE expression * @access private */ function _sql_like_expression($expression) { return $expression; } /** * Build db-specific query data * @access private */ function _sql_custom_build($stage, $data) { return $data; } /** * return sql error array * @private */ function _sql_error() { return array( 'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id), 'code' => '' ); } /** * Close sql connection * @private */ function _sql_close() { return @pg_close($this->db_connect_id); } /** * Build db-specific report * @private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @pg_query($this->db_connect_id, $query); while ($void = @pg_fetch_assoc($result, NULL)) { // Take the time spent on parsing rows into account } @pg_free_result($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } } // if ... defined // Connect to DB $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { mx_message_die(CRITICAL_ERROR, "Could not connect to the database"); } ?> --- NEW FILE: mysql4.php --- <?php /** * * @package DBal * @version $Id: mysql4.php,v 1.1 2008/12/31 01:44:18 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_mysql4')) { define('SQL_LAYER', 'mysql4'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; /** * @package DBal * MySQL4 Database Abstraction Layer * Compatible with: * MySQL 4.0+ * MySQL 4.1+ * MySQL 5.0+ */ class dbal_mysql4 extends dbal { var $mysql_version; var $multi_insert = true; /** * Connect to server */ /** * Connect to server * @access public */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); if ($this->db_connect_id && $this->dbname != '') { if (@mysql_select_db($this->dbname, $this->db_connect_id)) { // Determine what version we are using and if it natively supports UNICODE $this->mysql_version = mysql_get_server_info($this->db_connect_id); if (version_compare($this->mysql_version, '4.1.3', '>=')) { $this->sql_layer = 'mysql4'; @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); // enforce strict mode on databases that support it if (version_compare($this->mysql_version, '5.0.2', '>=')) { $result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id); $row = @mysql_fetch_assoc($result); @mysql_free_result($result); $modes = array_map('trim', explode(',', $row['sql_mode'])); // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES if (!in_array('TRADITIONAL', $modes)) { if (!in_array('STRICT_ALL_TABLES', $modes)) { $modes[] = 'STRICT_ALL_TABLES'; } if (!in_array('STRICT_TRANS_TABLES', $modes)) { $modes[] = 'STRICT_TRANS_TABLES'; } } $mode = implode(',', $modes); @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); } } else if (version_compare($this->mysql_version, '4.0.0', '>=')) { $this->sql_layer = 'mysql4'; } else //if (version_compare($this->mysql_version, '4.0.0', '<')) { $this->sql_layer = 'mysql'; } return $this->db_connect_id; } } return $this->sql_error(''); } /** * Version information about used database */ function sql_server_info() { return 'MySQL ' . $this->mysql_version; } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @mysql_query('BEGIN', $this->db_connect_id); $this->transaction = true; break; case 'commit': $result = @mysql_query('COMMIT', $this->db_connect_id); $this->transaction = false; if (!$result) { @mysql_query('ROLLBACK', $this->db_connect_id); } break; case 'rollback': $result = @mysql_query('ROLLBACK', $this->db_connect_id); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $mx_cache; // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->query_result = ($cache_ttl && method_exists($mx_cache, 'sql_load')) ? $mx_cache->sql_load($query) : false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false) { $this->sql_error($query); } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } if ($cache_ttl && method_exists($mx_cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $mx_cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } else if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { // Because MySQL 4.1+ no longer supports -1 in LIMIT queries we set it to the maximum value $total = '18446744073709551615'; } $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysql_num_rows($query_id) : false; } /** * Return number of affected rows */ function sql_affectedrows() { return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false; } /** * Fetch current row */ function sql_fetchrow($query_id = false) { global $mx_cache; if (!$query_id) { $query_id = $this->query_result; } if (isset($mx_cache->sql_rowset[$query_id])) { return $mx_cache->sql_fetchrow($query_id); } return ($query_id) ? @mysql_fetch_assoc($query_id) : false; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum === false) { $row = $this->sql_fetchrow($query_id); return isset($row[$field]) ? $row[$field] : false; } else { return @mysql_result($query_id, $rownum, $field); } } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysql_data_seek($query_id, $rownum) : false; } /** * Get last inserted id after insert statement */ function sql_nextid() { return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false; } /** * Free sql result */ function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); return @mysql_free_result($query_id); } return false; } /** * Escape string used in sql query */ function sql_escape($msg) { if (!$this->db_connect_id) { return @mysql_real_escape_string($msg); } return @mysql_real_escape_string($msg, $this->db_connect_id); } /** * Build LIKE expression * @access private */ function _sql_like_expression($expression) { return $expression; } /** * Build db-specific query data * @access private */ function _sql_custom_build($stage, $data) { switch ($stage) { case 'FROM': $data = '(' . $data . ')'; break; } return $data; } /** * return sql error array * @private */ function _sql_error() { if (!$this->db_connect_id) { return array( 'message' => @mysql_error(), 'code' => @mysql_errno() ); } return array( 'message' => @mysql_error($this->db_connect_id), 'code' => @mysql_errno($this->db_connect_id) ); } /** * Close sql connection * @private */ function _sql_close() { return @mysql_close($this->db_connect_id); } /** * Build db-specific report * @private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': $explain_query = $query; if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } else if (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $query, $m)) { $explain_query = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2]; } if (preg_match('/^SELECT/', $explain_query)) { $html_table = false; if ($result = @mysql_query("EXPLAIN $explain_query", $this->db_connect_id)) { while ($row = @mysql_fetch_assoc($result)) { $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); } } @mysql_free_result($result); if ($html_table) { $this->html_hold .= '</table>'; } } break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @mysql_query($query, $this->db_connect_id); while ($void = @mysql_fetch_assoc($result)) { // Take the time spent on parsing rows into account } @mysql_free_result($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } } // if ... define // Connect to DB $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { message_die(CRITICAL_ERROR, "Could not connect to the database"); } ?> --- NEW FILE: firebird.php --- <?php /** * * @package DBal * @version $Id: firebird.php,v 1.1 2008/12/31 01:44:17 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_firebird')) { define('SQL_LAYER', 'firebird'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** * @package DBal * Firebird/Interbase Database Abstraction Layer * Minimum Requirement is Firebird 1.5+/Interbase 7.1+ */ class dbal_firebird extends dbal { var $last_query_text = ''; /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3); return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($this->server . ':' . $this->dbname, $this->user, $sqlpassword, false, false, 3); $this->service_handle = (function_exists('ibase_service_attach')) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $this->transaction = true; break; case 'commit': $result = @ibase_commit(); $this->transaction = false; if (!$result) { @ibase_rollback(); } break; case 'rollback': $result = @ibase_rollback(); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $mx_cache; $this->last_query_text = $query; $this->query_result = ($cache_ttl && method_exists($mx_cache, 'sql_load')) ? $mx_cache->sql_load($query) : false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @ibase_query($this->db_connect_id, $query)) === false) { $this->sql_error($query); } // TODO: have to debug the commit states in firebird if (!$this->transaction) { @ibase_commit_ret(); } if ($cache_ttl && method_exists($mx_cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $mx_cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; $query = 'SELECT FIRST ' . $total . ((!empty($offset)) ? ' SKIP ' . $offset : '') . substr($query, 6); return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { return false; } /** * Return number of affected rows */ function sql_affectedrows() { // PHP 5+ function if (function_exists('ibase_affected_rows')) { return ($this->query_result) ? @ibase_affected_rows($this->query_result) : false; } else { return false; //($this->query_result) ? true : false; } } /** * Fetch current row */ function sql_fetchrow($query_id = false) { global $mx_cache; if (!$query_id) { $query_id = $this->query_result; } if (isset($mx_cache->sql_rowset[$query_id])) { return $mx_cache->sql_fetchrow($query_id); } $row = array(); $cur_row = @ibase_fetch_object($query_id, IBASE_TEXT); if (!$cur_row) { return false; } foreach (get_object_vars($cur_row) as $key => $value) { $row[strtolower($key)] = trim(str_replace("\\0", "\0", str_replace("\\n", "\n", $value))); } return (sizeof($row)) ? $row : false; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum !== false) { $this->sql_rowseek($rownum, $query_id); } $row = $this->sql_fetchrow($query_id); return isset($row[$field]) ? $row[$field] : false; } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } /* $this->sql_freeresult($query_id); $query_id = $this->sql_query($this->last_query_text); if (!$query_id) { return false; } */ // We do not fetch the row for rownum == 0 because then the next resultset would be the second row for ($i = 0; $i < $rownum; $i++) { if (!$this->sql_fetchrow($query_id)) { return false; } } return true; } /** * Get last inserted id after insert statement */ function sql_nextid() { $query_id = $this->query_result; if ($query_id && $this->last_query_text != '') { if ($this->query_result && preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#is', $this->last_query_text, $tablename)) { $query = "SELECT GEN_ID('" . $tablename[1] . "_gen', 0) AS new_id FROM RDB\$DATABASE"; if (!($temp_q_id = @ibase_query($this->db_connect_id, $query))) { return false; } $temp_result = @ibase_fetch_object($temp_q_id); @ibase_free_result($temp_q_id); return ($temp_result) ? $temp_result->last_value : false; } } return false; } /** * Free sql result */ function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if (!$this->transaction && $query_id) { $this->sql_transaction('commit'); } if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); return @ibase_free_result($query_id); } return false; } /** * Escape string used in sql query */ function sql_escape($msg) { return (@ini_get('magic_quotes_sybase') || strtolower(@ini_get('magic_quotes_sybase')) == 'on') ? str_replace('\\\'', '\'', addslashes($msg)) : str_replace('\'', '\'\'', stripslashes($msg)); } /** * return sql error array * @private */ function _sql_error() { return array( 'message' => @ibase_errmsg(), 'code' => '' ); } /** * Build LIKE expression * @access private */ function _sql_like_expression($expression) { return $expression . " ESCAPE '\\'"; } /** * Build db-specific query data * @access private */ function _sql_custom_build($stage, $data) { return $data; } /** * Close sql connection * @private */ function _sql_close() { return @ibase_close($this->db_connect_id); } /** * Build db-specific report * @private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @ibase_query($this->db_connect_id, $query); while ($void = @ibase_fetch_object($result, IBASE_TEXT)) { // Take the time spent on parsing rows into account } @ibase_freeresult($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } } // if ... define // Connect to DB $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { mx_message_die(CRITICAL_ERROR, "Could not connect to the database"); } ?> --- NEW FILE: mssql.php --- <?php /** * * @package DBal * @version $Id: mssql.php,v 1.1 2008/12/31 01:44:17 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_mssql')) { define('SQL_LAYER', 'mssql'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** * @package DBal * MSSQL Database Abstraction Layer * Minimum Requirement is MSSQL 2000+ */ class dbal_mssql extends dbal { /** * Connect to server */ /** * Connect to server */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; if (UTF_STATUS === 'phpbb3') { @ini_set('mssql.charset', 'UTF-8'); // enforce strict mode on databases that support it } @ini_set('mssql.textlimit', 2147483647); @ini_set('mssql.textsize', 2147483647); if (version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.1', '>='))) { $this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mssql_connect($this->server, $this->user, $sqlpassword, $new_link); } else { $this->db_connect_id = ($this->persistency) ? @mssql_pconnect($this->server, $this->user, $sqlpassword) : @mssql_connect($this->server, $this->user, $sqlpassword); } if ($this->db_connect_id && $this->dbname != '') { if (!@mssql_select_db($this->dbname, $this->db_connect_id)) { @mssql_close($this->db_connect_id); return false; } } return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error(''); } /** * Version information about used database */ function sql_server_info() { $result_id = @mssql_query("SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')", $this->db_connect_id); $row = false; if ($result_id) { $row = @mssql_fetch_assoc($result_id); @mssql_free_result($result_id); } if ($row) { return 'MSSQL<br />' . implode(' ', $row); } return 'MSSQL'; } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @mssql_query('BEGIN TRANSACTION', $this->db_connect_id); $this->transaction = true; break; case 'commit': $result = @mssql_query('commit', $this->db_connect_id); $this->transaction = false; if (!$result) { @mssql_query('ROLLBACK', $this->db_connect_id); } break; case 'rollback': $result = @mssql_query('ROLLBACK', $this->db_connect_id); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $mx_cache; // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->query_result = ($cache_ttl && method_exists($mx_cache, 'sql_load')) ? $mx_cache->sql_load($query) : false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @mssql_query($query, $this->db_connect_id)) === false) { $this->sql_error($query); } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } if ($cache_ttl && method_exists($mx_cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $mx_cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } else if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { $total = -1; } $row_offset = ($total) ? $offset : ''; $num_rows = ($total) ? $total : $offset; $query = 'SELECT TOP ' . ($row_offset + $num_rows) . ' ' . substr($query, 6); return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mssql_num_rows($query_id) : false; } /** * Return number of affected rows */ function sql_affectedrows() { return ($this->db_connect_id) ? @mssql_rows_affected($this->db_connect_id) : false; } /** * Fetch current row */ function sql_fetchrow($query_id = false) { global $mx_cache; if (!$query_id) { $query_id = $this->query_result; } if (isset($mx_cache->sql_rowset[$query_id])) { return $mx_cache->sql_fetchrow($query_id); } $row = @mssql_fetch_assoc($query_id); // I hope i am able to remove this later... hopefully only a PHP or MSSQL bug if ($row) { foreach ($row as $key => $value) { $row[$key] = ($value === ' ') ? '' : $value; } } return $row; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum !== false) { $this->sql_rowseek($rownum, $query_id); } $row = $this->sql_fetchrow($query_id); return isset($row[$field]) ? $row[$field] : false; } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mssql_data_seek($query_id, $rownum) : false; } /** * Get last inserted id after insert statement */ function sql_nextid() { $result_id = @mssql_query('SELECT @@IDENTITY', $this->db_connect_id); if ($result_id) { if (@mssql_fetch_assoc($result_id)) { $id = @mssql_result($result_id, 1); @mssql_free_result($result_id); return $id; } @mssql_free_result($result_id); } return false; } /** * Free sql result */ function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if (isset($this->open_queries[$query_id])) { unset($this->open_queries[$query_id]); return @mssql_free_result($query_id); } return false; } /** * Escape string used in sql query */ function sql_escape($msg) { return str_replace("'", "''", str_replace('\\', '\\\\', $msg)); } /** * return sql error array * @private */ function _sql_error() { return array( 'message' => @mssql_get_last_message($this->db_connect_id), 'code' => '' ); } /** * Build LIKE expression * @access private */ function _sql_like_expression($expression) { return $expression . " ESCAPE '\\'"; } /** * Build db-specific query data * @access private */ function _sql_custom_build($stage, $data) { return $data; } /** * Close sql connection * @private */ function _sql_close() { return @mssql_close($this->db_connect_id); } /** * Build db-specific report * @private */ function _sql_report($mode, $query = '') { switch ($mode) { case 'start': break; case 'fromcache': $endtime = explode(' ', microtime()); $endtime = $endtime[0] + $endtime[1]; $result = @mssql_query($query, $this->db_connect_id); while ($void = @mssql_fetch_assoc($result)) { // Take the time spent on parsing rows into account } @mssql_free_result($result); $splittime = explode(' ', microtime()); $splittime = $splittime[0] + $splittime[1]; $this->sql_report('record_fromcache', $query, $endtime, $splittime); break; } } } } // if ... define // Connect to DB $db = new $sql_db(); if(!$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, false)) { mx_message_die(CRITICAL_ERROR, "Could not connect to the database"); } ?> --- NEW FILE: index.htm --- <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> </body> </html> --- NEW FILE: mysql.php --- <?php /** * * @package DBal * @version $Id: mysql.php,v 1.1 2008/12/31 01:44:18 orynider Exp $ * @copyright (c) 2005 phpBB Group * @copyright (c) 2002-2008 MX-Publisher Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @link http://www.mx-publisher.com * */ /** */ if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); } /** * @ignore */ //if (!defined('SQL_LAYER')) if (!is_object('dbal_mysql')) { define('SQL_LAYER', 'mysql'); include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); $sql_db = 'dbal_' . $dbms; // Repopulated for multiple db connections /** * @package DBal * MySQL Database Abstraction Layer * Minimum Requirement is 3.23+/4.0+/4.1+ */ class dbal_mysql extends dbal { var $mysql_version; var $multi_insert = true; /** * Connect to server * @access public */ function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) { $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); $this->dbname = $database; $this->sql_layer = 'mysql4'; $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $sqlpassword, $new_link) : @mysql_connect($this->server, $this->user, $sqlpassword, $new_link); if ($this->db_connect_id && $this->dbname != '') { if (@mysql_select_db($this->dbname, $this->db_connect_id)) { // Determine what version we are using and if it natively supports UNICODE $this->mysql_version = mysql_get_server_info($this->db_connect_id); if (version_compare($this->mysql_version, '4.1.3', '>=')) { if (UTF_STATUS === 'phpbb3') { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); // enforce strict mode on databases that support it } if (version_compare($this->mysql_version, '5.0.2', '>=')) { $result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id); $row = @mysql_fetch_assoc($result); @mysql_free_result($result); $modes = array_map('trim', explode(',', $row['sql_mode'])); // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES if (!in_array('TRADITIONAL', $modes)) { if (!in_array('STRICT_ALL_TABLES', $modes)) { $modes[] = 'STRICT_ALL_TABLES'; } if (!in_array('STRICT_TRANS_TABLES', $modes)) { $modes[] = 'STRICT_TRANS_TABLES'; } } $mode = implode(',', $modes); @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); } } else if (version_compare($this->mysql_version, '4.0.0', '<')) { $this->sql_layer = 'mysql'; } return $this->db_connect_id; } } return $this->sql_error(); } /** * Version information about used database */ function sql_server_info() { return 'MySQL ' . $this->mysql_version; } /** * sql transaction */ function sql_transaction($status = 'begin') { switch ($status) { case 'begin': $result = @mysql_query('BEGIN', $this->db_connect_id); $this->transaction = true; break; case 'commit': $result = @mysql_query('COMMIT', $this->db_connect_id); $this->transaction = false; if (!$result) { @mysql_query('ROLLBACK', $this->db_connect_id); } break; case 'rollback': $result = @mysql_query('ROLLBACK', $this->db_connect_id); $this->transaction = false; break; default: $result = true; } return $result; } /** * Base query method */ function sql_query($query = '', $cache_ttl = 0) { if ($query != '') { global $mx_cache; // EXPLAIN only in extra debug mode if (defined('DEBUG_EXTRA')) { $this->sql_report('start', $query); } $this->query_result = ($cache_ttl && method_exists($mx_cache, 'sql_load')) ? $mx_cache->sql_load($query) : false; if (!$this->query_result) { $this->num_queries++; if (($this->query_result = @mysql_query($query, $this->db_connect_id)) === false) { $this->sql_error($query); } if (defined('DEBUG_EXTRA')) { $this->sql_report('stop', $query); } if ($cache_ttl && method_exists($mx_cache, 'sql_save')) { $this->open_queries[(int) $this->query_result] = $this->query_result; $mx_cache->sql_save($query, $this->query_result, $cache_ttl); } else if (strpos($query, 'SELECT') === 0 && $this->query_result) { $this->open_queries[(int) $this->query_result] = $this->query_result; } } else if (defined('DEBUG_EXTRA')) { $this->sql_report('fromcache', $query); } } else { return false; } return ($this->query_result) ? $this->query_result : false; } /** * Build LIMIT query */ function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) { if ($query != '') { $this->query_result = false; // if $total is set to 0 we do not want to limit the number of rows if ($total == 0) { $total = -1; } $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); return $this->sql_query($query, $cache_ttl); } else { return false; } } /** * Return number of rows * Not used within core code */ function sql_numrows($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysql_num_rows($query_id) : false; } /** * Return number of affected rows */ function sql_affectedrows() { return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false; } /** * Fetch current row */ function sql_fetchrow($query_id = false) { global $mx_cache; if (!$query_id) { $query_id = $this->query_result; } if (isset($mx_cache->sql_rowset[$query_id])) { return $mx_cache->sql_fetchrow($query_id); } return ($query_id) ? @mysql_fetch_assoc($query_id) : false; } /** * Fetch field * if rownum is false, the current row is used, else it is pointing to the row (zero-based) */ function sql_fetchfield($field, $rownum = false, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if ($query_id) { if ($rownum === false) { $row = $this->sql_fetchrow($query_id); return isset($row[$field]) ? $row[$field] : false; } else { return @mysql_result($query_id, $rownum, $field); } } return false; } /** * Seek to given row number * rownum is zero-based */ function sql_rowseek($rownum, $query_id = false) { if (!$query_id) { $query_id = $this->query_result; } return ($query_id) ? @mysql_data_seek($query_id, $rownum) : false; } /** * Get last inserted id after insert statement */ function sql_nextid() { return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false; } /** * Free sql result */ function sql_freeresult($query_id = false) { if (!$query_id) { $query_id = $this->query_result; } if (isset($this->open_queries[(int) $query_id])) { unset($this->open_queries[(int) $query_id]); return @mysql_free_result($query_id); } return false; } /** * Escape string used in sql query */ function sql_escape($msg) { if (!$this->db_connect_id) { return @mysql_real_escape_string($m... [truncated message content] |