1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 07:35:29 +02:00

turn on strict mode for databases that support it

git-svn-id: file:///svn/phpbb/trunk@8029 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
David M 2007-08-14 12:27:35 +00:00
parent 0c948afde2
commit 8ab583dce0
2 changed files with 51 additions and 1 deletions

View File

@ -57,6 +57,31 @@ class dbal_mysql extends dbal
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($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', '<'))
{

View File

@ -45,6 +45,31 @@ 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)
{
$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;
}
@ -314,7 +339,7 @@ class dbal_mysqli extends dbal
if (strpos(mysqli_get_server_info($this->db_connect_id), 'community') !== false)
{
$ver = mysqli_get_server_version($this->db_connect_id);
if ($ver >= 50037 && $ver < 51000)
if ($ver >= 50037 && $ver < 50100)
{
$test_prof = true;
}