phpBB

Code Changes

File: includes/db/mysql.php

  Unmodified   Added   Modified   Removed
Line 29Line 29
*/
class dbal_mysql extends dbal
{

*/
class dbal_mysql extends dbal
{

	var $mysql_version;

 
	var $multi_insert = true;

	var $multi_insert = true;

 
	var $connect_error = '';


/**
* Connect to server


/**
* Connect to server

Line 45Line 45

$this->sql_layer = 'mysql4';



$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->persistency)
{
if (!function_exists('mysql_pconnect'))
{
$this->connect_error = 'mysql_pconnect function does not exist, is mysql extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @mysql_pconnect($this->server, $this->user, $sqlpassword);
}
else
{
if (!function_exists('mysql_connect'))
{
$this->connect_error = 'mysql_connect function does not exist, is mysql extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @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 ($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 (version_compare($this->sql_server_info(true), '4.1.0', '>='))



				{
@mysql_query("SET NAMES 'utf8'", $this->db_connect_id);

				{
@mysql_query("SET NAMES 'utf8'", $this->db_connect_id);

 


					// enforce strict mode on databases that support it

					// enforce strict mode on databases that support it

					if (version_compare($this->mysql_version, '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);

					{
$result = @mysql_query('SELECT @@session.sql_mode AS sql_mode', $this->db_connect_id);
$row = @mysql_fetch_assoc($result);

Line 83Line 99
						@mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id);
}
}

						@mysql_query("SET SESSION sql_mode='{$mode}'", $this->db_connect_id);
}
}

				else if (version_compare($this->mysql_version, '4.0.0', '<'))

				else if (version_compare($this->sql_server_info(true), '4.0.0', '<'))

				{
$this->sql_layer = 'mysql';
}

				{
$this->sql_layer = 'mysql';
}

Line 97Line 113

/**
* Version information about used database


/**
* 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()

	function sql_server_info($raw = false, $use_cache = true)

	{

	{

		return 'MySQL ' . $this->mysql_version;

















		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;

	}

/**

	}

/**

Line 183Line 218
			return false;
}


			return false;
}


		return ($this->query_result) ? $this->query_result : false;

		return $this->query_result;

	}

/**

	}

/**

Line 299Line 334
		}

return @mysql_real_escape_string($msg, $this->db_connect_id);

		}

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;

	}

/**

	}

/**

Line 332Line 437
	*/
function _sql_error()
{

	*/
function _sql_error()
{

		if (!$this->db_connect_id)








		if ($this->db_connect_id)
{
$error = array(
'message' => @mysql_error($this->db_connect_id),
'code' => @mysql_errno($this->db_connect_id),
);
}
else if (function_exists('mysql_error'))

		{

		{

			return array(

			$error = array(

				'message'	=> @mysql_error(),

				'message'	=> @mysql_error(),

				'code'		=> @mysql_errno()

				'code'		=> @mysql_errno(),

			);
}

			);
}


return array(
'message' => @mysql_error($this->db_connect_id),
'code' => @mysql_errno($this->db_connect_id)


		else
{
$error = array(
'message' => $this->connect_error,
'code' => '',

		);

		);

 
		}

return $error;

	}

/**

	}

/**

Line 367Line 483
		if ($test_prof === null)
{
$test_prof = false;

		if ($test_prof === null)
{
$test_prof = false;

			if (strpos($this->mysql_version, 'community') !== false)
{
$ver = substr($this->mysql_version, 0, strpos($this->mysql_version, '-'));
if (version_compare($ver, '5.0.37', '>=') && version_compare($ver, '5.1', '<'))

			if (version_compare($this->sql_server_info(true), '5.0.37', '>=') && version_compare($this->sql_server_info(true), '5.1', '<'))




				{
$test_prof = true;

				{
$test_prof = true;

				}

 
			}
}


			}
}