From 85055ac97fa57ca339924cef719115d85bdf6c2e Mon Sep 17 00:00:00 2001 From: David M Date: Thu, 3 Jan 2008 17:00:40 +0000 Subject: oh boy... - Migrate code base to PHP 5.1+ git-svn-id: file:///svn/phpbb/trunk@8295 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 2d689f86f9..840d40b03d 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -362,11 +362,12 @@ class dbal_mysql extends dbal function _sql_report($mode, $query = '') { static $test_prof; + static $test_extend; // current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING if ($test_prof === null) { - $test_prof = false; + $test_prof = $test_extend = false; if (strpos($this->mysql_version, 'community') !== false) { $ver = substr($this->mysql_version, 0, strpos($this->mysql_version, '-')); @@ -375,6 +376,11 @@ class dbal_mysql extends dbal $test_prof = true; } } + + if (version_compare($ver, '4.1.1', '>=')) + { + $test_extend = true; + } } switch ($mode) @@ -401,7 +407,7 @@ class dbal_mysql extends dbal @mysql_query('SET profiling = 1;', $this->db_connect_id); } - if ($result = @mysql_query("EXPLAIN $explain_query", $this->db_connect_id)) + if ($result = @mysql_query('EXPLAIN ' . (($test_extend) ? 'EXTENDED ' : '') . "$explain_query", $this->db_connect_id)) { while ($row = @mysql_fetch_assoc($result)) { @@ -415,6 +421,27 @@ class dbal_mysql extends dbal $this->html_hold .= ''; } + if ($test_extend) + { + $html_table = false; + + if ($result = @mysql_query('SHOW WARNINGS', $this->db_connect_id)) + { + $this->html_hold .= '
'; + 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 .= ''; + } + } + + if ($test_prof) { $html_table = false; -- cgit v1.2.1 From af738dbc2a48713f59779410955282aa5760b741 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 4 Jan 2008 18:35:49 +0000 Subject: Ch-ch-ch-changes - Made us more DB independent by making many queries capability based instead of DB specific - Finished PHP5ifying of the acm_file class, now with some (hopefully) enhancements to its performance - Sped up viewforum considerably (also goes towards mcp_forum) I really hope I didn't explode CVS... git-svn-id: file:///svn/phpbb/trunk@8301 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 840d40b03d..108a75c0cc 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -32,6 +32,9 @@ class dbal_mysql extends dbal var $mysql_version; var $multi_insert = true; + // Supports multiple table deletion + var $multi_table_deletion = false; + /** * Connect to server * @access public @@ -301,6 +304,20 @@ class dbal_mysql extends dbal return @mysql_real_escape_string($msg, $this->db_connect_id); } + /** + * Expose a DBMS specific function + */ + function sql_function($type, $col) + { + switch ($type) + { + case 'length_varchar': + case 'length_text': + return 'LENGTH(' . $col . ')'; + break; + } + } + /** * Build LIKE expression * @access private -- cgit v1.2.1 From 57645ad5bc2469e166cb3e5d54628d87ffa74c42 Mon Sep 17 00:00:00 2001 From: David M Date: Sun, 6 Jan 2008 02:21:44 +0000 Subject: the end of an era... - MySQL < 4.1.3 support is removed - renamed mysql4 to mysql, no need to cause confusion - changed the cfg cacher, reduces file system lookups and include count by two on every page load git-svn-id: file:///svn/phpbb/trunk@8307 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 59 +++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 108a75c0cc..0c949309a1 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -19,21 +19,18 @@ if (!defined('IN_PHPBB')) include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); /** -* MySQL4 Database Abstraction Layer +* MySQL Database Abstraction Layer * Compatible with: -* MySQL 3.23+ -* MySQL 4.0+ * MySQL 4.1+ * MySQL 5.0+ * @package dbal */ class dbal_mysql extends dbal { - var $mysql_version; var $multi_insert = true; // Supports multiple table deletion - var $multi_table_deletion = false; + var $multi_table_deletion = true; /** * Connect to server @@ -46,49 +43,37 @@ class dbal_mysql extends dbal $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', '>=')) + @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + // enforce strict mode on databases that support it + if (version_compare(mysql_get_server_info($this->db_connect_id), '5.0.2', '>=')) { - @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'])); + $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)) + // TRADITIONAL includes STRICT_ALL_TABLES and STRICT_TRANS_TABLES + if (!in_array('TRADITIONAL', $modes)) + { + if (!in_array('STRICT_ALL_TABLES', $modes)) { - if (!in_array('STRICT_ALL_TABLES', $modes)) - { - $modes[] = 'STRICT_ALL_TABLES'; - } - - if (!in_array('STRICT_TRANS_TABLES', $modes)) - { - $modes[] = 'STRICT_TRANS_TABLES'; - } + $modes[] = 'STRICT_ALL_TABLES'; } - $mode = implode(',', $modes); - @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); + if (!in_array('STRICT_TRANS_TABLES', $modes)) + { + $modes[] = 'STRICT_TRANS_TABLES'; + } } - } - else if (version_compare($this->mysql_version, '4.0.0', '<')) - { - $this->sql_layer = 'mysql'; + + $mode = implode(',', $modes); + @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); } return $this->db_connect_id; @@ -103,7 +88,7 @@ class dbal_mysql extends dbal */ function sql_server_info() { - return 'MySQL ' . $this->mysql_version; + return 'MySQL ' . mysql_get_server_info($this->db_connect_id); } /** -- cgit v1.2.1 From 2928574ed46334bb8dbbb6612a62db3c3654ba12 Mon Sep 17 00:00:00 2001 From: David M Date: Mon, 7 Jan 2008 15:19:38 +0000 Subject: - a few tiny clean ups - a new MS SQL DBAL, it does not work so hot because of issues with the extension it depends on git-svn-id: file:///svn/phpbb/trunk@8313 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 0c949309a1..17daf7093c 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -32,6 +32,8 @@ class dbal_mysql extends dbal // Supports multiple table deletion var $multi_table_deletion = true; + var $dbms_type = 'mysql'; + /** * Connect to server * @access public -- cgit v1.2.1 From 7b262babcd5c862c3068b08da8bba5f48bd5f36a Mon Sep 17 00:00:00 2001 From: David M Date: Sun, 3 Feb 2008 10:19:04 +0000 Subject: Alright, this should give some improved performance :) This is the end of random seek access to rows. If you have a compelling reason as to why they should stay, contact me. Else, they are gone forevermore... The following API calls are deprecated: acm::sql_rowseek() -> no replacement $db->sql_fetchfield($field, $rownum = false, $query_id = false) -> $db->sql_fetchfield($field, $query_id = false) Initial tests show that phpBB3 over four percent of memory against phpBB3.1 on an empty board. So far so good :) Other cool things: db2, MS SQL ODBC and MS SQL 2005 all use less memory because they do not need to reference the last executed query to handle random access seeks :) P.S. The crazy people using SVN: please report any issues with the new way we itterate through caches, I do not want to miss anything :) git-svn-id: file:///svn/phpbb/trunk@8372 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 17daf7093c..1014fe6780 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -223,27 +223,6 @@ class dbal_mysql extends dbal return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false; } - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - return ($query_id !== false) ? @mysql_data_seek($query_id, $rownum) : false; - } - /** * Get last inserted id after insert statement */ -- cgit v1.2.1 From 2deee69e2f9ecd239e59bf651e73c6780227c824 Mon Sep 17 00:00:00 2001 From: David M Date: Wed, 2 Apr 2008 08:28:21 +0000 Subject: Some neat stuff, the new DBAL function has the potential of removing somewhere in the ballpark of 40% of all the DBAL code. It combines a few very common idioms into one statement, allowing us to implicitly use prepared statements. Short term advantages are the ability to remove the gross code that attempts to work around DB2, Oracle and Firebird. Long term advantages include removing the burden of sanitizing data (at least on input) from our end and placing it on shoulders of the backend PHP driver. Also included is a new posting API I am working on. It is not a real API in so much as it is a backend that a "nice" API could use. User submitted functions are welcome :) It represents a massive simplification in post and topic accounting and a generalization of concepts like "soft deletion" as it works across both topics and posts (yes, this has preliminary support for soft deletions). The only "interesting" problem left is global topics, this has yet to be solved. Enough talk, time for sleep. P.S. Sorry if I broke stuff, was not done on purpose :) git-svn-id: file:///svn/phpbb/trunk@8485 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 1014fe6780..1e32b8178a 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -284,6 +284,21 @@ class dbal_mysql extends dbal } } + function sql_handle_data($type, $table, $data, $where = '') + { + if ($type === 'UPDATE') + { + $this->sql_query('INSERT INTO ' . $table . ' ' . + $this->sql_build_array('INSERT', $data)); + } + else + { + $this->sql_query('UPDATE ' . $table . ' + SET ' . $db->sql_build_array('UPDATE', $data) . + $where); + } + } + /** * Build LIKE expression * @access private -- cgit v1.2.1 From 2f4a618900e2c3b6ea14c68cbeb5897cd2ac1a04 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 29 May 2008 12:25:56 +0000 Subject: ok... i hope i haven't messed too much with the code and everything is still working. Changes: - Ascraeus now uses constants for the phpbb root path and the php extension. This ensures more security for external applications and modifications (no more overwriting of root path and extension possible through insecure mods and register globals enabled) as well as no more globalizing needed. - A second change implemented here is an additional short-hand-notation for append_sid(). It is allowed to omit the root path and extension now (for example calling append_sid('memberlist')) - in this case the root path and extension get added automatically. The hook is called after these are added. git-svn-id: file:///svn/phpbb/trunk@8572 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 1e32b8178a..fd4dc74674 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -16,7 +16,7 @@ if (!defined('IN_PHPBB')) exit; } -include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx); +include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); /** * MySQL Database Abstraction Layer -- cgit v1.2.1 From f2abefeaed267a405ae1ccafba7ce2a52794fadc Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 2 Sep 2008 13:36:48 +0000 Subject: Merge in r8758, r8807, r8808, r8809 git-svn-id: file:///svn/phpbb/trunk@8810 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index fd4dc74674..540009cc6c 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -173,7 +173,7 @@ class dbal_mysql extends dbal return false; } - return ($this->query_result) ? $this->query_result : false; + return $this->query_result; } /** -- cgit v1.2.1 From 3a330753f413c3e024163f8f401f327bc2f9930c Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 4 Sep 2008 14:10:03 +0000 Subject: Get real dbms version instead of relying on php internal functions which only grab the local library version git-svn-id: file:///svn/phpbb/trunk@8821 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 54 +++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 540009cc6c..ff45a403e9 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -52,26 +52,18 @@ class dbal_mysql extends dbal if (@mysql_select_db($this->dbname, $this->db_connect_id)) { @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + // enforce strict mode on databases that support it - if (version_compare(mysql_get_server_info($this->db_connect_id), '5.0.2', '>=')) + if (version_compare($this->sql_server_info(true), '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)) { - if (!in_array('STRICT_ALL_TABLES', $modes)) - { - $modes[] = 'STRICT_ALL_TABLES'; - } + $modes[] = 'STRICT_ALL_TABLES'; + } - if (!in_array('STRICT_TRANS_TABLES', $modes)) - { - $modes[] = 'STRICT_TRANS_TABLES'; - } + if (!in_array('STRICT_TRANS_TABLES', $modes)) + { + $modes[] = 'STRICT_TRANS_TABLES'; } $mode = implode(',', $modes); @@ -87,10 +79,28 @@ class dbal_mysql extends dbal /** * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version */ - function sql_server_info() + function sql_server_info($raw = false) { - return 'MySQL ' . mysql_get_server_info($this->db_connect_id); + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false) + { + $result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id); + $row = @mysql_fetch_assoc($result); + @mysql_free_result($result); + + $this->sql_server_version = $row['version']; + + if (!empty($cache)) + { + $cache->put('mysql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version; } /** @@ -366,13 +376,9 @@ class dbal_mysql extends dbal if ($test_prof === null) { $test_prof = $test_extend = false; - if (strpos($this->mysql_version, 'community') !== false) + if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<')) { - $ver = substr($this->mysql_version, 0, strpos($this->mysql_version, '-')); - if (version_compare($ver, '5.0.37', '>=') && version_compare($ver, '5.1', '<')) - { - $test_prof = true; - } + $test_prof = true; } if (version_compare($ver, '4.1.1', '>=')) -- cgit v1.2.1 From b55f9854e770ba7c37e0e1914c8570c856cbecf3 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 19 Jan 2009 16:07:17 +0000 Subject: update mysql DBAL to be supported now too git-svn-id: file:///svn/phpbb/trunk@9280 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 348 +++++++++++++++++++------------------------- 1 file changed, 147 insertions(+), 201 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index ff45a403e9..97a7c2a4ea 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -16,8 +16,6 @@ if (!defined('IN_PHPBB')) exit; } -include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); - /** * MySQL Database Abstraction Layer * Compatible with: @@ -25,78 +23,115 @@ include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); * MySQL 5.0+ * @package dbal */ -class dbal_mysql extends dbal +class phpbb_dbal_mysql extends phpbb_dbal { - var $multi_insert = true; - - // Supports multiple table deletion - var $multi_table_deletion = true; + /** + * @var string Database type. No distinction between versions or used extensions. + */ + public $dbms_type = 'mysql'; - var $dbms_type = 'mysql'; + /** + * @var array Database type map, column layout information + */ + public $dbms_type_map = array( + 'INT:' => 'int(%d)', + 'BINT' => 'bigint(20)', + 'UINT' => 'mediumint(8) UNSIGNED', + 'UINT:' => 'int(%d) UNSIGNED', + 'TINT:' => 'tinyint(%d)', + 'USINT' => 'smallint(4) UNSIGNED', + 'BOOL' => 'tinyint(1) UNSIGNED', + 'VCHAR' => 'varchar(255)', + 'VCHAR:' => 'varchar(%d)', + 'CHAR:' => 'char(%d)', + 'XSTEXT' => 'text', + 'XSTEXT_UNI'=> 'varchar(100)', + 'STEXT' => 'text', + 'STEXT_UNI' => 'varchar(255)', + 'TEXT' => 'text', + 'TEXT_UNI' => 'text', + 'MTEXT' => 'mediumtext', + 'MTEXT_UNI' => 'mediumtext', + 'TIMESTAMP' => 'int(11) UNSIGNED', + 'DECIMAL' => 'decimal(5,2)', + 'DECIMAL:' => 'decimal(%d,2)', + 'PDECIMAL' => 'decimal(6,3)', + 'PDECIMAL:' => 'decimal(%d,3)', + 'VCHAR_UNI' => 'varchar(255)', + 'VCHAR_UNI:'=> 'varchar(%d)', + 'VARBINARY' => 'varbinary(255)', + ); /** - * Connect to server - * @access public + * Connect to server. See {@link phpbb_dbal::sql_connect() sql_connect()} for details. */ - function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false) + public function sql_connect($server, $user, $password, $database, $port = false, $persistency = false , $new_link = false) { $this->persistency = $persistency; - $this->user = $sqluser; - $this->server = $sqlserver . (($port) ? ':' . $port : ''); + $this->user = $user; + $this->server = $server . (($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); + $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $password, $new_link) : @mysql_connect($this->server, $this->user, $password, $new_link); - if ($this->db_connect_id && $this->dbname != '') + if (!$this->db_connect_id || !$this->dbname) { - if (@mysql_select_db($this->dbname, $this->db_connect_id)) - { - @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + return $this->sql_error(''); + } - // enforce strict mode on databases that support it - if (version_compare($this->sql_server_info(true), '5.0.2', '>=')) - { - if (!in_array('STRICT_ALL_TABLES', $modes)) - { - $modes[] = 'STRICT_ALL_TABLES'; - } + if (!@mysql_select_db($this->dbname, $this->db_connect_id)) + { + return $this->sql_error(''); + } - if (!in_array('STRICT_TRANS_TABLES', $modes)) - { - $modes[] = 'STRICT_TRANS_TABLES'; - } + @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + + // enforce strict mode on databases that support it + if (version_compare($this->sql_server_info(true), '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'])); - $mode = implode(',', $modes); - @mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id); + // 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'; } - return $this->db_connect_id; + 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); } - return $this->sql_error(''); + return $this->db_connect_id; } /** - * Version information about used database - * @param bool $raw if true, only return the fetched sql_server_version - * @return string sql server version + * Version information about used database. See {@link phpbb_dbal::sql_server_info() sql_server_info()} for details. */ - function sql_server_info($raw = false) + public function sql_server_info($raw = false) { - global $cache; - - if (empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false) + if (!phpbb::registered('acm') || ($this->sql_server_version = phpbb::$acm->get('#mysql_version')) === false) { $result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id); $row = @mysql_fetch_assoc($result); @mysql_free_result($result); - $this->sql_server_version = $row['version']; + $this->sql_server_version = trim($row['version']); - if (!empty($cache)) + if (phpbb::registered('acm')) { - $cache->put('mysql_version', $this->sql_server_version); + phpbb::$acm->put('#mysql_version', $this->sql_server_version); } } @@ -104,10 +139,41 @@ class dbal_mysql extends dbal } /** - * SQL Transaction - * @access private + * DB-specific base query method. See {@link phpbb_dbal::_sql_query() _sql_query()} for details. + */ + protected function _sql_query($query) + { + return @mysql_query($query, $this->db_connect_id); + } + + /** + * Build LIMIT query and run it. See {@link phpbb_dbal::_sql_query_limit() _sql_query_limit()} for details. + */ + protected function _sql_query_limit($query, $total, $offset, $cache_ttl) + { + // 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); + } + + /** + * Close sql connection. See {@link phpbb_dbal::_sql_close() _sql_close()} for details. + */ + protected function _sql_close() + { + return @mysql_close($this->db_connect_id); + } + + /** + * SQL Transaction. See {@link phpbb_dbal::_sql_transaction() _sql_transaction()} for details. */ - function _sql_transaction($status = 'begin') + protected function _sql_transaction($status) { switch ($status) { @@ -128,149 +194,49 @@ class dbal_mysql extends dbal } /** - * Base query method - * - * @param string $query Contains the SQL query which shall be executed - * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache - * @return mixed When casted to bool the returned value returns true on success and false on failure - * - * @access public - */ - function sql_query($query = '', $cache_ttl = 0) - { - if ($query != '') - { - global $cache; - - // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) - { - $this->sql_report('start', $query); - } - - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; - $this->sql_add_num_queries($this->query_result); - - if ($this->query_result === false) - { - 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($cache, 'sql_save')) - { - $this->open_queries[(int) $this->query_result] = $this->query_result; - $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; - } - - /** - * Build LIMIT query + * Return number of affected rows. See {@link phpbb_dbal::sql_affectedrows() sql_affectedrows()} for details. */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + public function sql_affectedrows() { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - // Having a value of -1 was always a bug - $total = '18446744073709551615'; - } - - $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); - - return $this->sql_query($query, $cache_ttl); + return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false; } /** - * Return number of affected rows + * Get last inserted id after insert statement. See {@link phpbb_dbal::sql_nextid() sql_nextid()} for details. */ - function sql_affectedrows() + public function sql_nextid() { - return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false; + return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false; } /** - * Fetch current row + * Fetch current row. See {@link phpbb_dbal::_sql_fetchrow() _sql_fetchrow()} for details. */ - function sql_fetchrow($query_id = false) + protected function _sql_fetchrow($query_id) { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_fetchrow($query_id); - } - - return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false; + return @mysql_fetch_assoc($query_id); } /** - * Get last inserted id after insert statement + * Free query result. See {@link phpbb_dbal::_sql_freeresult() _sql_freeresult()} for details. */ - function sql_nextid() + protected function _sql_freeresult($query_id) { - return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false; + return @mysql_free_result($query_id); } /** - * Free sql result + * Correctly adjust LIKE expression for special characters. See {@link phpbb_dbal::_sql_like_expression() _sql_like_expression()} for details. */ - function sql_freeresult($query_id = false) + protected function _sql_like_expression($expression) { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_freeresult($query_id); - } - - if (isset($this->open_queries[(int) $query_id])) - { - unset($this->open_queries[(int) $query_id]); - return @mysql_free_result($query_id); - } - - return false; + return $expression; } /** - * Escape string used in sql query + * Escape string used in sql query. See {@link phpbb_dbal::sql_escape() sql_escape()} for details. */ - function sql_escape($msg) + public function sql_escape($msg) { if (!$this->db_connect_id) { @@ -281,9 +247,9 @@ class dbal_mysql extends dbal } /** - * Expose a DBMS specific function + * Expose a DBMS specific function. See {@link phpbb_dbal::sql_function() sql_function()} for details. */ - function sql_function($type, $col) + public function sql_function($type, $col) { switch ($type) { @@ -294,35 +260,27 @@ class dbal_mysql extends dbal } } - function sql_handle_data($type, $table, $data, $where = '') + /** + * Handle data by using prepared statements. See {@link phpbb_dbal::sql_handle_data() sql_handle_data()} for details. + * @todo implement correctly by using types. ;) + */ + public function sql_handle_data($type, $table, $data, $where = '') { if ($type === 'UPDATE') { - $this->sql_query('INSERT INTO ' . $table . ' ' . - $this->sql_build_array('INSERT', $data)); + $where = ($where) ? ' WHERE ' . $where : ''; + $this->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', $data) . $where); } else { - $this->sql_query('UPDATE ' . $table . ' - SET ' . $db->sql_build_array('UPDATE', $data) . - $where); + $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $data)); } } /** - * Build LIKE expression - * @access private - */ - function _sql_like_expression($expression) - { - return $expression; - } - - /** - * Build db-specific query data - * @access private + * Build DB-specific query bits. See {@link phpbb_dbal::_sql_custom_build() _sql_custom_build()} for details. */ - function _sql_custom_build($stage, $data) + protected function _sql_custom_build($stage, $data) { switch ($stage) { @@ -333,12 +291,11 @@ class dbal_mysql extends dbal return $data; } - + /** - * return sql error array - * @access private + * return sql error array. See {@link phpbb_dbal::_sql_error() _sql_error()} for details. */ - function _sql_error() + protected function _sql_error() { if (!$this->db_connect_id) { @@ -355,19 +312,9 @@ class dbal_mysql extends dbal } /** - * Close sql connection - * @access private - */ - function _sql_close() - { - return @mysql_close($this->db_connect_id); - } - - /** - * Build db-specific report - * @access private + * Run DB-specific code to build SQL Report to explain queries, show statistics and runtime information. See {@link phpbb_dbal::_sql_report() _sql_report()} for details. */ - function _sql_report($mode, $query = '') + protected function _sql_report($mode, $query = '') { static $test_prof; static $test_extend; @@ -381,7 +328,7 @@ class dbal_mysql extends dbal $test_prof = true; } - if (version_compare($ver, '4.1.1', '>=')) + if (version_compare($this->sql_server_info(true), '4.1.1', '>=')) { $test_extend = true; } @@ -445,7 +392,6 @@ class dbal_mysql extends dbal } } - if ($test_prof) { $html_table = false; -- cgit v1.2.1 From 578beb75ef0b63680ffd9fdb216df87d4cf098d5 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 21 Jan 2009 17:04:17 +0000 Subject: put sql_handle_data() into dbal and let DBMS who support this overwrite it. David: would be nice if you could have a look at it later. ;) git-svn-id: file:///svn/phpbb/trunk@9285 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 97a7c2a4ea..ac0384d523 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -71,6 +71,7 @@ class phpbb_dbal_mysql extends phpbb_dbal $this->user = $user; $this->server = $server . (($port) ? ':' . $port : ''); $this->dbname = $database; + $this->port = $port; $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $password, $new_link) : @mysql_connect($this->server, $this->user, $password, $new_link); @@ -262,20 +263,10 @@ class phpbb_dbal_mysql extends phpbb_dbal /** * Handle data by using prepared statements. See {@link phpbb_dbal::sql_handle_data() sql_handle_data()} for details. - * @todo implement correctly by using types. ;) - */ public function sql_handle_data($type, $table, $data, $where = '') { - if ($type === 'UPDATE') - { - $where = ($where) ? ' WHERE ' . $where : ''; - $this->sql_query('UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', $data) . $where); - } - else - { - $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $data)); - } } + */ /** * Build DB-specific query bits. See {@link phpbb_dbal::_sql_custom_build() _sql_custom_build()} for details. -- cgit v1.2.1 From bf8ac19eaa8d74f9dfd6d597190f5664e7339382 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:13:59 +0000 Subject: Move trunk/phpBB to old_trunk/phpBB git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 447 -------------------------------------------- 1 file changed, 447 deletions(-) delete mode 100644 phpBB/includes/db/mysql.php (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php deleted file mode 100644 index ac0384d523..0000000000 --- a/phpBB/includes/db/mysql.php +++ /dev/null @@ -1,447 +0,0 @@ - 'int(%d)', - 'BINT' => 'bigint(20)', - 'UINT' => 'mediumint(8) UNSIGNED', - 'UINT:' => 'int(%d) UNSIGNED', - 'TINT:' => 'tinyint(%d)', - 'USINT' => 'smallint(4) UNSIGNED', - 'BOOL' => 'tinyint(1) UNSIGNED', - 'VCHAR' => 'varchar(255)', - 'VCHAR:' => 'varchar(%d)', - 'CHAR:' => 'char(%d)', - 'XSTEXT' => 'text', - 'XSTEXT_UNI'=> 'varchar(100)', - 'STEXT' => 'text', - 'STEXT_UNI' => 'varchar(255)', - 'TEXT' => 'text', - 'TEXT_UNI' => 'text', - 'MTEXT' => 'mediumtext', - 'MTEXT_UNI' => 'mediumtext', - 'TIMESTAMP' => 'int(11) UNSIGNED', - 'DECIMAL' => 'decimal(5,2)', - 'DECIMAL:' => 'decimal(%d,2)', - 'PDECIMAL' => 'decimal(6,3)', - 'PDECIMAL:' => 'decimal(%d,3)', - 'VCHAR_UNI' => 'varchar(255)', - 'VCHAR_UNI:'=> 'varchar(%d)', - 'VARBINARY' => 'varbinary(255)', - ); - - /** - * Connect to server. See {@link phpbb_dbal::sql_connect() sql_connect()} for details. - */ - public function sql_connect($server, $user, $password, $database, $port = false, $persistency = false , $new_link = false) - { - $this->persistency = $persistency; - $this->user = $user; - $this->server = $server . (($port) ? ':' . $port : ''); - $this->dbname = $database; - $this->port = $port; - - $this->db_connect_id = ($this->persistency) ? @mysql_pconnect($this->server, $this->user, $password, $new_link) : @mysql_connect($this->server, $this->user, $password, $new_link); - - if (!$this->db_connect_id || !$this->dbname) - { - return $this->sql_error(''); - } - - if (!@mysql_select_db($this->dbname, $this->db_connect_id)) - { - return $this->sql_error(''); - } - - @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); - - // enforce strict mode on databases that support it - if (version_compare($this->sql_server_info(true), '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); - } - - return $this->db_connect_id; - } - - /** - * Version information about used database. See {@link phpbb_dbal::sql_server_info() sql_server_info()} for details. - */ - public function sql_server_info($raw = false) - { - if (!phpbb::registered('acm') || ($this->sql_server_version = phpbb::$acm->get('#mysql_version')) === false) - { - $result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id); - $row = @mysql_fetch_assoc($result); - @mysql_free_result($result); - - $this->sql_server_version = trim($row['version']); - - if (phpbb::registered('acm')) - { - phpbb::$acm->put('#mysql_version', $this->sql_server_version); - } - } - - return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version; - } - - /** - * DB-specific base query method. See {@link phpbb_dbal::_sql_query() _sql_query()} for details. - */ - protected function _sql_query($query) - { - return @mysql_query($query, $this->db_connect_id); - } - - /** - * Build LIMIT query and run it. See {@link phpbb_dbal::_sql_query_limit() _sql_query_limit()} for details. - */ - protected function _sql_query_limit($query, $total, $offset, $cache_ttl) - { - // 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); - } - - /** - * Close sql connection. See {@link phpbb_dbal::_sql_close() _sql_close()} for details. - */ - protected function _sql_close() - { - return @mysql_close($this->db_connect_id); - } - - /** - * SQL Transaction. See {@link phpbb_dbal::_sql_transaction() _sql_transaction()} for details. - */ - protected function _sql_transaction($status) - { - switch ($status) - { - case 'begin': - return @mysql_query('BEGIN', $this->db_connect_id); - break; - - case 'commit': - return @mysql_query('COMMIT', $this->db_connect_id); - break; - - case 'rollback': - return @mysql_query('ROLLBACK', $this->db_connect_id); - break; - } - - return true; - } - - /** - * Return number of affected rows. See {@link phpbb_dbal::sql_affectedrows() sql_affectedrows()} for details. - */ - public function sql_affectedrows() - { - return ($this->db_connect_id) ? @mysql_affected_rows($this->db_connect_id) : false; - } - - /** - * Get last inserted id after insert statement. See {@link phpbb_dbal::sql_nextid() sql_nextid()} for details. - */ - public function sql_nextid() - { - return ($this->db_connect_id) ? @mysql_insert_id($this->db_connect_id) : false; - } - - /** - * Fetch current row. See {@link phpbb_dbal::_sql_fetchrow() _sql_fetchrow()} for details. - */ - protected function _sql_fetchrow($query_id) - { - return @mysql_fetch_assoc($query_id); - } - - /** - * Free query result. See {@link phpbb_dbal::_sql_freeresult() _sql_freeresult()} for details. - */ - protected function _sql_freeresult($query_id) - { - return @mysql_free_result($query_id); - } - - /** - * Correctly adjust LIKE expression for special characters. See {@link phpbb_dbal::_sql_like_expression() _sql_like_expression()} for details. - */ - protected function _sql_like_expression($expression) - { - return $expression; - } - - /** - * Escape string used in sql query. See {@link phpbb_dbal::sql_escape() sql_escape()} for details. - */ - public 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); - } - - /** - * Expose a DBMS specific function. See {@link phpbb_dbal::sql_function() sql_function()} for details. - */ - public function sql_function($type, $col) - { - switch ($type) - { - case 'length_varchar': - case 'length_text': - return 'LENGTH(' . $col . ')'; - break; - } - } - - /** - * Handle data by using prepared statements. See {@link phpbb_dbal::sql_handle_data() sql_handle_data()} for details. - public function sql_handle_data($type, $table, $data, $where = '') - { - } - */ - - /** - * Build DB-specific query bits. See {@link phpbb_dbal::_sql_custom_build() _sql_custom_build()} for details. - */ - protected function _sql_custom_build($stage, $data) - { - switch ($stage) - { - case 'FROM': - $data = '(' . $data . ')'; - break; - } - - return $data; - } - - /** - * return sql error array. See {@link phpbb_dbal::_sql_error() _sql_error()} for details. - */ - protected 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) - ); - } - - /** - * Run DB-specific code to build SQL Report to explain queries, show statistics and runtime information. See {@link phpbb_dbal::_sql_report() _sql_report()} for details. - */ - protected function _sql_report($mode, $query = '') - { - static $test_prof; - static $test_extend; - - // current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING - if ($test_prof === null) - { - $test_prof = $test_extend = false; - if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<')) - { - $test_prof = true; - } - - if (version_compare($this->sql_server_info(true), '4.1.1', '>=')) - { - $test_extend = true; - } - } - - 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; - - // begin profiling - if ($test_prof) - { - @mysql_query('SET profiling = 1;', $this->db_connect_id); - } - - if ($result = @mysql_query('EXPLAIN ' . (($test_extend) ? 'EXTENDED ' : '') . "$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 .= ''; - } - - if ($test_extend) - { - $html_table = false; - - if ($result = @mysql_query('SHOW WARNINGS', $this->db_connect_id)) - { - $this->html_hold .= '
'; - 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 .= ''; - } - } - - if ($test_prof) - { - $html_table = false; - - // get the last profile - if ($result = @mysql_query('SHOW PROFILE ALL;', $this->db_connect_id)) - { - $this->html_hold .= '
'; - while ($row = @mysql_fetch_assoc($result)) - { - // make HTML safe - if (!empty($row['Source_function'])) - { - $row['Source_function'] = str_replace(array('<', '>'), array('<', '>'), $row['Source_function']); - } - - // remove unsupported features - foreach ($row as $key => $val) - { - if ($val === null) - { - unset($row[$key]); - } - } - $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); - } - } - @mysql_free_result($result); - - if ($html_table) - { - $this->html_hold .= ''; - } - - @mysql_query('SET profiling = 0;', $this->db_connect_id); - } - } - - 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; - } - } -} - -?> \ No newline at end of file -- cgit v1.2.1 From 2e17e448deed073f8614bb555a8ef20c57291c2a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:14:59 +0000 Subject: Copy 3.0.x branch to trunk git-svn-id: file:///svn/phpbb/trunk@10211 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/db/mysql.php | 491 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 491 insertions(+) create mode 100644 phpBB/includes/db/mysql.php (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php new file mode 100644 index 0000000000..c03b38708c --- /dev/null +++ b/phpBB/includes/db/mysql.php @@ -0,0 +1,491 @@ +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 + if (version_compare($this->sql_server_info(true), '4.1.0', '>=')) + { + @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); + + // enforce strict mode on databases that support it + if (version_compare($this->sql_server_info(true), '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->sql_server_info(true), '4.0.0', '<')) + { + $this->sql_layer = 'mysql'; + } + + return $this->db_connect_id; + } + } + + return $this->sql_error(''); + } + + /** + * Version information about used database + * @param bool $raw if true, only return the fetched sql_server_version + * @return string sql server version + */ + function sql_server_info($raw = false) + { + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false) + { + $result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id); + $row = @mysql_fetch_assoc($result); + @mysql_free_result($result); + + $this->sql_server_version = $row['version']; + + if (!empty($cache)) + { + $cache->put('mysql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version; + } + + /** + * SQL Transaction + * @access private + */ + function _sql_transaction($status = 'begin') + { + switch ($status) + { + case 'begin': + return @mysql_query('BEGIN', $this->db_connect_id); + break; + + case 'commit': + return @mysql_query('COMMIT', $this->db_connect_id); + break; + + case 'rollback': + return @mysql_query('ROLLBACK', $this->db_connect_id); + break; + } + + return true; + } + + /** + * Base query method + * + * @param string $query Contains the SQL query which shall be executed + * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache + * @return mixed When casted to bool the returned value returns true on success and false on failure + * + * @access public + */ + function sql_query($query = '', $cache_ttl = 0) + { + if ($query != '') + { + global $cache; + + // EXPLAIN only in extra debug mode + if (defined('DEBUG_EXTRA')) + { + $this->sql_report('start', $query); + } + + $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; + $this->sql_add_num_queries($this->query_result); + + if ($this->query_result === false) + { + 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($cache, 'sql_save')) + { + $this->open_queries[(int) $this->query_result] = $this->query_result; + $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; + } + + /** + * Build LIMIT query + */ + function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) + { + $this->query_result = false; + + // if $total is set to 0 we do not want to limit the number of rows + if ($total == 0) + { + // Having a value of -1 was always a bug + $total = '18446744073709551615'; + } + + $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); + + return $this->sql_query($query, $cache_ttl); + } + + /** + * 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 $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_fetchrow($query_id); + } + + return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false; + } + + /** + * Seek to given row number + * rownum is zero-based + */ + function sql_rowseek($rownum, &$query_id) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_rowseek($rownum, $query_id); + } + + return ($query_id !== false) ? @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) + { + global $cache; + + if ($query_id === false) + { + $query_id = $this->query_result; + } + + if (isset($cache->sql_rowset[$query_id])) + { + return $cache->sql_freeresult($query_id); + } + + 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 + * @access 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 + * @access private + */ + function _sql_close() + { + return @mysql_close($this->db_connect_id); + } + + /** + * Build db-specific report + * @access private + */ + function _sql_report($mode, $query = '') + { + static $test_prof; + + // current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING + if ($test_prof === null) + { + $test_prof = false; + if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<')) + { + $test_prof = true; + } + } + + 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; + + // begin profiling + if ($test_prof) + { + @mysql_query('SET profiling = 1;', $this->db_connect_id); + } + + 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 .= ''; + } + + if ($test_prof) + { + $html_table = false; + + // get the last profile + if ($result = @mysql_query('SHOW PROFILE ALL;', $this->db_connect_id)) + { + $this->html_hold .= '
'; + while ($row = @mysql_fetch_assoc($result)) + { + // make HTML safe + if (!empty($row['Source_function'])) + { + $row['Source_function'] = str_replace(array('<', '>'), array('<', '>'), $row['Source_function']); + } + + // remove unsupported features + foreach ($row as $key => $val) + { + if ($val === null) + { + unset($row[$key]); + } + } + $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); + } + } + @mysql_free_result($result); + + if ($html_table) + { + $this->html_hold .= ''; + } + + @mysql_query('SET profiling = 0;', $this->db_connect_id); + } + } + + 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; + } + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From af5b9a96409d788733fcb1ff367e0c7fb0583702 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Tue, 9 Nov 2010 08:59:25 +0100 Subject: [ticket/9556] Drop php closing tags, add trailing newline Closing tags converted using Oleg's script. remove-php-end-tags.py -a . Trailing newlines added using the following where $ext is file extension. find . -type f -name "*.$ext" -print | xargs printf "e %s\nw\n" | ed -s; Extensions: php, css, html, js, xml. PHPBB3-9556 --- phpBB/includes/db/mysql.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 1e24c79577..d0537e2fe9 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -488,5 +488,3 @@ class dbal_mysql extends dbal } } } - -?> \ No newline at end of file -- cgit v1.2.1 From 7a04c9048c110f0bd21ea3e9e869e17b408d640e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 31 Dec 2011 13:32:52 +0000 Subject: [ticket/9916] Updating header license and removing Version $Id$ PHPBB3-9916 --- phpBB/includes/db/mysql.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index d0537e2fe9..317b8d123d 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -2,9 +2,8 @@ /** * * @package dbal -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From fe1f21d1a55ac15b278d99c3a73a8e3424a38fd5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 2 Jul 2012 23:11:21 +0200 Subject: [ticket/10942] Use ANSI SQL standard || in dbal.php PHPBB3-10942 --- phpBB/includes/db/mysql.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index eb38e3e913..3cda5cc1e0 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -119,6 +119,14 @@ class dbal_mysql extends dbal return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version; } + /** + * {@inheritDoc} + */ + function sql_concatenate($expr1, $expr2) + { + return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; + } + /** * SQL Transaction * @access private -- cgit v1.2.1 From 6776feb0de667340d640744462d00436f893c45f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 4 Jul 2012 14:05:03 +0200 Subject: [ticket/10942] Add access modifiers PHPBB3-10942 --- phpBB/includes/db/mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 3cda5cc1e0..8d1f805870 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -122,7 +122,7 @@ class dbal_mysql extends dbal /** * {@inheritDoc} */ - function sql_concatenate($expr1, $expr2) + public function sql_concatenate($expr1, $expr2) { return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; } -- cgit v1.2.1 From 90a957ad26f52e26c3979464c5ac15b1fd0fcc28 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 17:43:43 +0200 Subject: [ticket/11015] Make DBAL classes autoloadable PHPBB3-11015 This allows us to just create the object without having to include the driver first. However, it also means that users must specify the full class name in config.php --- phpBB/includes/db/mysql.php | 567 -------------------------------------------- 1 file changed, 567 deletions(-) delete mode 100644 phpBB/includes/db/mysql.php (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php deleted file mode 100644 index 8d1f805870..0000000000 --- a/phpBB/includes/db/mysql.php +++ /dev/null @@ -1,567 +0,0 @@ -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) : @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 - if (version_compare($this->sql_server_info(true), '4.1.0', '>=')) - { - @mysql_query("SET NAMES 'utf8'", $this->db_connect_id); - - // enforce strict mode on databases that support it - if (version_compare($this->sql_server_info(true), '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->sql_server_info(true), '4.0.0', '<')) - { - $this->sql_layer = 'mysql'; - } - - return $this->db_connect_id; - } - } - - return $this->sql_error(''); - } - - /** - * Version information about used database - * @param bool $raw if true, only return the fetched sql_server_version - * @param bool $use_cache If true, it is safe to retrieve the value from the cache - * @return string sql server version - */ - function sql_server_info($raw = false, $use_cache = true) - { - global $cache; - - if (!$use_cache || empty($cache) || ($this->sql_server_version = $cache->get('mysql_version')) === false) - { - $result = @mysql_query('SELECT VERSION() AS version', $this->db_connect_id); - $row = @mysql_fetch_assoc($result); - @mysql_free_result($result); - - $this->sql_server_version = $row['version']; - - if (!empty($cache) && $use_cache) - { - $cache->put('mysql_version', $this->sql_server_version); - } - } - - return ($raw) ? $this->sql_server_version : 'MySQL ' . $this->sql_server_version; - } - - /** - * {@inheritDoc} - */ - public function sql_concatenate($expr1, $expr2) - { - return 'CONCAT(' . $expr1 . ', ' . $expr2 . ')'; - } - - /** - * SQL Transaction - * @access private - */ - function _sql_transaction($status = 'begin') - { - switch ($status) - { - case 'begin': - return @mysql_query('BEGIN', $this->db_connect_id); - break; - - case 'commit': - return @mysql_query('COMMIT', $this->db_connect_id); - break; - - case 'rollback': - return @mysql_query('ROLLBACK', $this->db_connect_id); - break; - } - - return true; - } - - /** - * Base query method - * - * @param string $query Contains the SQL query which shall be executed - * @param int $cache_ttl Either 0 to avoid caching or the time in seconds which the result shall be kept in cache - * @return mixed When casted to bool the returned value returns true on success and false on failure - * - * @access public - */ - function sql_query($query = '', $cache_ttl = 0) - { - if ($query != '') - { - global $cache; - - // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) - { - $this->sql_report('start', $query); - } - - $this->query_result = ($cache_ttl && method_exists($cache, 'sql_load')) ? $cache->sql_load($query) : false; - $this->sql_add_num_queries($this->query_result); - - if ($this->query_result === false) - { - 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($cache, 'sql_save')) - { - $this->open_queries[(int) $this->query_result] = $this->query_result; - $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; - } - - /** - * Build LIMIT query - */ - function _sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0) - { - $this->query_result = false; - - // if $total is set to 0 we do not want to limit the number of rows - if ($total == 0) - { - // Having a value of -1 was always a bug - $total = '18446744073709551615'; - } - - $query .= "\n LIMIT " . ((!empty($offset)) ? $offset . ', ' . $total : $total); - - return $this->sql_query($query, $cache_ttl); - } - - /** - * 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 $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_fetchrow($query_id); - } - - return ($query_id !== false) ? @mysql_fetch_assoc($query_id) : false; - } - - /** - * Seek to given row number - * rownum is zero-based - */ - function sql_rowseek($rownum, &$query_id) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_rowseek($rownum, $query_id); - } - - return ($query_id !== false) ? @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) - { - global $cache; - - if ($query_id === false) - { - $query_id = $this->query_result; - } - - if (isset($cache->sql_rowset[$query_id])) - { - return $cache->sql_freeresult($query_id); - } - - 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); - } - - /** - * Gets the estimated number of rows in a specified table. - * - * @param string $table_name Table name - * - * @return string Number of rows in $table_name. - * Prefixed with ~ if estimated (otherwise exact). - * - * @access public - */ - function get_estimated_row_count($table_name) - { - $table_status = $this->get_table_status($table_name); - - if (isset($table_status['Engine'])) - { - if ($table_status['Engine'] === 'MyISAM') - { - return $table_status['Rows']; - } - else if ($table_status['Engine'] === 'InnoDB' && $table_status['Rows'] > 100000) - { - return '~' . $table_status['Rows']; - } - } - - return parent::get_row_count($table_name); - } - - /** - * Gets the exact number of rows in a specified table. - * - * @param string $table_name Table name - * - * @return string Exact number of rows in $table_name. - * - * @access public - */ - function get_row_count($table_name) - { - $table_status = $this->get_table_status($table_name); - - if (isset($table_status['Engine']) && $table_status['Engine'] === 'MyISAM') - { - return $table_status['Rows']; - } - - return parent::get_row_count($table_name); - } - - /** - * Gets some information about the specified table. - * - * @param string $table_name Table name - * - * @return array - * - * @access protected - */ - function get_table_status($table_name) - { - $sql = "SHOW TABLE STATUS - LIKE '" . $this->sql_escape($table_name) . "'"; - $result = $this->sql_query($sql); - $table_status = $this->sql_fetchrow($result); - $this->sql_freeresult($result); - - return $table_status; - } - - /** - * 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 - * @access 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 - * @access private - */ - function _sql_close() - { - return @mysql_close($this->db_connect_id); - } - - /** - * Build db-specific report - * @access private - */ - function _sql_report($mode, $query = '') - { - static $test_prof; - - // current detection method, might just switch to see the existance of INFORMATION_SCHEMA.PROFILING - if ($test_prof === null) - { - $test_prof = false; - if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<')) - { - $test_prof = true; - } - } - - 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; - - // begin profiling - if ($test_prof) - { - @mysql_query('SET profiling = 1;', $this->db_connect_id); - } - - 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 .= ''; - } - - if ($test_prof) - { - $html_table = false; - - // get the last profile - if ($result = @mysql_query('SHOW PROFILE ALL;', $this->db_connect_id)) - { - $this->html_hold .= '
'; - while ($row = @mysql_fetch_assoc($result)) - { - // make HTML safe - if (!empty($row['Source_function'])) - { - $row['Source_function'] = str_replace(array('<', '>'), array('<', '>'), $row['Source_function']); - } - - // remove unsupported features - foreach ($row as $key => $val) - { - if ($val === null) - { - unset($row[$key]); - } - } - $html_table = $this->sql_report('add_select_row', $query, $html_table, $row); - } - } - @mysql_free_result($result); - - if ($html_table) - { - $this->html_hold .= ''; - } - - @mysql_query('SET profiling = 0;', $this->db_connect_id); - } - } - - 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; - } - } -} -- cgit v1.2.1 From 65bafb22810038fd51e22fd8168775afd86c2e74 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 18:08:40 +0200 Subject: [ticket/11015] Add BC files for the drivers PHPBB3-11015 --- phpBB/includes/db/mysql.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 phpBB/includes/db/mysql.php (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php new file mode 100644 index 0000000000..dcd69cf51a --- /dev/null +++ b/phpBB/includes/db/mysql.php @@ -0,0 +1,19 @@ + Date: Mon, 12 Nov 2012 10:38:28 +0100 Subject: [ticket/11015] Remove old dbal classes PHPBB3-11015 --- phpBB/includes/db/mysql.php | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 phpBB/includes/db/mysql.php (limited to 'phpBB/includes/db/mysql.php') diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php deleted file mode 100644 index dcd69cf51a..0000000000 --- a/phpBB/includes/db/mysql.php +++ /dev/null @@ -1,19 +0,0 @@ -