diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 34a1261c2a..77d45ebd43 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -74,6 +74,11 @@ class dbal var $any_char; var $one_char; + /** + * Exact version of the DBAL, directly queried + */ + var $sql_server_version = false; + /** * Constructor */ diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 429c0f2d4f..2f577244eb 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -41,26 +41,42 @@ class dbal_firebird extends dbal $this->persistency = $persistency; $this->user = $sqluser; $this->server = $sqlserver . (($port) ? ':' . $port : ''); - $this->dbname = $database; + $this->dbname = str_replace('\\', '/', $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); + // There are three possibilities to connect to an interbase db + if (!$this->server) + { + $use_database = $this->dbname; + } + else if (strpos($this->server, '//') === 0) + { + $use_database = $this->server . $this->dbname; + } + else + { + $use_database = $this->server . ':' . $this->dbname; + } - $this->service_handle = (strtolower($this->user) == 'sysdba') ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; + $this->db_connect_id = ($this->persistency) ? @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3); + + $this->service_handle = (strtolower($this->user) == 'sysdba' && $this->server) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false; return ($this->db_connect_id) ? $this->db_connect_id : $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() + function sql_server_info($raw = false) { if ($this->service_handle !== false) { return @ibase_server_info($this->service_handle, IBASE_SVC_SERVER_VERSION); } - return 'Firebird/Interbase'; + return ($raw) ? '2.0' : 'Firebird/Interbase'; } /** diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index a2081891e4..7864f7a3d7 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -57,24 +57,38 @@ class dbal_mssql 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) { - $result_id = @mssql_query("SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')", $this->db_connect_id); + global $cache; - $row = false; - if ($result_id) + if (empty($cache) || ($this->sql_server_version = $cache->get('mssql_version')) === false) { - $row = @mssql_fetch_assoc($result_id); - @mssql_free_result($result_id); + $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); + } + + $this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0; + + if (!empty($cache)) + { + $cache->put('mssql_version', $this->sql_server_version); + } } - if ($row) + if ($raw) { - return 'MSSQL
' . implode(' ', $row); + return $this->sql_server_version; } - return 'MSSQL'; + return ($this->sql_server_version) ? 'MSSQL
' . $this->sql_server_version : 'MSSQL'; } /** diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index b2e6c8d583..d26dafdb52 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -73,24 +73,38 @@ class dbal_mssql_odbc 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) { - $result_id = @odbc_exec($this->db_connect_id, "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')"); + global $cache; - $row = false; - if ($result_id) + if (empty($cache) || ($this->sql_server_version = $cache->get('mssqlodbc_version')) === false) { - $row = @odbc_fetch_array($result_id); - @odbc_free_result($result_id); + $result_id = @odbc_exec($this->db_connect_id, "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')"); + + $row = false; + if ($result_id) + { + $row = @odbc_fetch_array($result_id); + @odbc_free_result($result_id); + } + + $this->sql_server_version = ($row) ? trim(implode(' ', $row)) : 0; + + if (!empty($cache)) + { + $cache->put('mssqlodbc_version', $this->sql_server_version); + } } - if ($row) + if ($raw) { - return 'MSSQL (ODBC)
' . implode(' ', $row); + return $this->sql_server_version; } - return 'MSSQL (ODBC)'; + return ($this->sql_server_version) ? 'MSSQL (ODBC)
' . $this->sql_server_version : 'MSSQL (ODBC)'; } /** 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', '>=')) diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index ff77299b46..11030508bd 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -51,12 +51,14 @@ class dbal_mysqli extends dbal if ($this->db_connect_id && $this->dbname != '') { @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) + if (version_compare($this->sql_server_info(true), '5.0.2', '>=')) { $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 @@ -84,10 +86,28 @@ class dbal_mysqli 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(i) ' . @mysqli_get_server_info($this->db_connect_id); + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('mysqli_version')) === false) + { + $result = @mysqli_query($this->db_connect_id, 'SELECT VERSION() AS version'); + $row = @mysqli_fetch_assoc($result); + @mysqli_free_result($result); + + $this->sql_server_version = $row['version']; + + if (!empty($cache)) + { + $cache->put('mysqli_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'MySQL(i) ' . $this->sql_server_version; } /** diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 411c2aa494..e0b04f4ce7 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -57,10 +57,31 @@ class dbal_oracle 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 @oci_server_version($this->db_connect_id); +/* + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('oracle_version')) === false) + { + $result = @ociparse($this->db_connect_id, 'SELECT * FROM v$version WHERE banner LIKE \'Oracle%\''); + @ociexecute($result, OCI_DEFAULT); + @ocicommit($this->db_connect_id); + + $row = array(); + @ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS); + @ocifreestatement($result); + $this->sql_server_version = trim($row['BANNER']); + + $cache->put('oracle_version', $this->sql_server_version); + } +*/ + $this->sql_server_version = @ociserverversion($this->db_connect_id); + + return $this->sql_server_version; } /** diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index 8ac0fa8300..2f6b5613c5 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -26,7 +26,6 @@ include_once(PHPBB_ROOT_PATH . 'includes/db/dbal.' . PHP_EXT); class dbal_postgres extends dbal { var $last_query_text = ''; - var $pgsql_version; var $dbms_type = 'postgres'; @@ -83,26 +82,17 @@ class dbal_postgres extends dbal if ($this->db_connect_id) { - // determine what version of PostgreSQL is running, we can be more efficient if they are running 8.2+ - $this->pgsql_version = @pg_parameter_status($this->db_connect_id, 'server_version'); - - if (!empty($this->pgsql_version) && $this->pgsql_version[0] >= '8') + if (version_compare($this->sql_server_info(true), '8.2', '>=')) { - if ($this->pgsql_version[2] >= '1') - { - $this->multi_table_deletion = true; - } - - if ($this->pgsql_version[2] >= '2') - { - $this->multi_insert = true; - } + $this->multi_table_deletion = true; + $this->multi_insert = true; } if ($schema !== '') { @pg_query($this->db_connect_id, 'SET search_path TO ' . $schema); } + return $this->db_connect_id; } @@ -111,10 +101,28 @@ class dbal_postgres 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 'PostgreSQL ' . $this->pgsql_version; + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('pgsql_version')) === false) + { + $query_id = @pg_query($this->db_connect_id, 'SELECT VERSION() AS version'); + $row = @pg_fetch_assoc($query_id, null); + @pg_free_result($query_id); + + $this->sql_server_version = (!empty($row['version'])) ? trim(substr($row['version'], 10)) : 0; + + if (!empty($cache)) + { + $cache->put('pgsql_version', $this->sql_server_version); + } + } + + return ($raw) ? $this->sql_server_version : 'PostgreSQL ' . $this->sql_server_version; } /** diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index df1180db8f..dc2701c1ce 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -49,18 +49,31 @@ class dbal_sqlite extends dbal if ($this->db_connect_id) { @sqlite_query('PRAGMA short_column_names = 1', $this->db_connect_id); +// @sqlite_query('PRAGMA encoding = "UTF-8"', $this->db_connect_id); } - return ($this->db_connect_id) ? true : array('message' => $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() + function sql_server_info($raw = false) { - return 'SQLite ' . @sqlite_libversion(); + global $cache; + + if (empty($cache) || ($this->sql_server_version = $cache->get('sqlite_version')) === false) + { + $result = @sqlite_query('SELECT sqlite_version() AS version', $this->db_connect_id); + $row = @sqlite_fetch_array($result, SQLITE_ASSOC); + + $this->sql_server_version = (!empty($row['version'])) ? $row['version'] : 0; + $cache->put('sqlite_version', $this->sql_server_version); + } + + return ($raw) ? $this->sql_server_version : 'SQLite ' . $this->sql_server_version; } /** diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index fe44433f33..319505d57a 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -681,7 +681,7 @@ class install_convert extends module // Thanks MySQL, for silently converting... case 'mysql': - if (version_compare($src_db->mysql_version, '4.1.3', '>=')) + if (version_compare($src_db->sql_server_info(true), '4.1.3', '>=')) { $convert->mysql_convert = true; } diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index b2bf0fb37f..1c3f490ccb 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1378,6 +1378,10 @@ class install_install extends module 'UPDATE ' . $data['table_prefix'] . "forums SET forum_last_post_time = $current_time", + + 'UPDATE ' . $data['table_prefix'] . "config + SET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "' + WHERE config_name = 'dbms_version'", ); if (@extension_loaded('gd') || can_load_dll('gd'))