Vergleich inc/db_mysql.php - 1.4.3 - 1.4.9

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 6Zeile 6
 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/about/license
*

 * Website: http://www.mybboard.net
* License: http://www.mybboard.net/about/license
*

 * $Id: db_mysql.php 4067 2008-08-04 03:59:08Z Tikitiki $

 * $Id: db_mysql.php 4304 2009-01-02 01:11:56Z chris $

 */

class DB_MySQL

 */

class DB_MySQL

Zeile 143Zeile 143
		{
$connections['read'][] = $config;
}

		{
$connections['read'][] = $config;
}

 
		else

		// Connecting to more than one server
{
// Specified multiple servers, but no specific read/write servers

		// Connecting to more than one server
{
// Specified multiple servers, but no specific read/write servers

Zeile 157Zeile 158
			else
{
$connections = $config;

			else
{
$connections = $config;

			}

			}

		}

		}





		$this->db_encoding = $config['encoding'];

// Actually connect to the specified servers

		$this->db_encoding = $config['encoding'];

// Actually connect to the specified servers

Zeile 171Zeile 172
			}

if(array_key_exists('hostname', $connections[$type]))

			}

if(array_key_exists('hostname', $connections[$type]))

			{

			{

				$details = $connections[$type];
unset($connections);
$connections[$type][] = $details;

				$details = $connections[$type];
unset($connections);
$connections[$type][] = $details;

Zeile 185Zeile 186
			{
$connect_function = "mysql_connect";
if($single_connection['pconnect'])

			{
$connect_function = "mysql_connect";
if($single_connection['pconnect'])

				{

				{

					$connect_function = "mysql_pconnect";
}


					$connect_function = "mysql_pconnect";
}


Zeile 213Zeile 214

// No write server was specified (simple connection or just multiple servers) - mirror write link
if(!array_key_exists('write', $connections))


// No write server was specified (simple connection or just multiple servers) - mirror write link
if(!array_key_exists('write', $connections))

		{

		{

			$this->write_link = &$this->read_link;

			$this->write_link = &$this->read_link;

		}


		}


		// Have no read connection?
if(!$this->read_link)

		// Have no read connection?
if(!$this->read_link)

		{

		{

			$this->error("[READ] Unable to connect to MySQL server");

			$this->error("[READ] Unable to connect to MySQL server");

		}

		}

		// No write?
else if(!$this->write_link)
{
$this->error("[WRITE] Unable to connect to MySQL server");

		// No write?
else if(!$this->write_link)
{
$this->error("[WRITE] Unable to connect to MySQL server");

		}


		}


		// Select databases

		// Select databases

		$this->select_db($config['database']);




		if(!$this->select_db($config['database']))
{
return false;
}


$this->current_link = &$this->read_link;
return $this->read_link;


$this->current_link = &$this->read_link;
return $this->read_link;

Zeile 256Zeile 260
		else
{
$success = $read_success;

		else
{
$success = $read_success;

		}

		}

		
if($success && $this->db_encoding)
{

		
if($success && $this->db_encoding)
{

Zeile 481Zeile 485

/**
* Return an error number.


/**
* Return an error number.

	 *

	 *

	 * @return int The error number of the current error.
*/
function error_number()

	 * @return int The error number of the current error.
*/
function error_number()

Zeile 489Zeile 493
		if($this->current_link)
{
return @mysql_errno($this->current_link);

		if($this->current_link)
{
return @mysql_errno($this->current_link);

		}

		}

		else
{
return @mysql_errno();

		else
{
return @mysql_errno();

		}
}


		}
}


	/**
* Return an error string.
*

	/**
* Return an error string.
*

Zeile 523Zeile 527
		if($this->error_reporting)
{
if(class_exists("errorHandler"))

		if($this->error_reporting)
{
if(class_exists("errorHandler"))

			{

			{

				global $error_handler;

if(!is_object($error_handler))

				global $error_handler;

if(!is_object($error_handler))

Zeile 543Zeile 547
			{
trigger_error("<strong>[SQL] [".$this->error_number()."] ".$this->error_string()."</strong><br />{$string}", E_USER_ERROR);
}

			{
trigger_error("<strong>[SQL] [".$this->error_number()."] ".$this->error_string()."</strong><br />{$string}", E_USER_ERROR);
}

 
		}
else
{
return false;

		}
}


		}
}






	/**
* Returns the number of affected rows in a query.
*
* @return int The number of affected rows.

	/**
* Returns the number of affected rows in a query.
*
* @return int The number of affected rows.

	 */

	 */

	function affected_rows()
{
return mysql_affected_rows($this->current_link);

	function affected_rows()
{
return mysql_affected_rows($this->current_link);

Zeile 592Zeile 600
		}

return $tables;

		}

return $tables;

	}


	}


	/**
* Check if a table exists in a database.
*

	/**
* Check if a table exists in a database.
*

Zeile 609Zeile 617
		$query = $this->write_query("
SHOW TABLES
LIKE '{$this->table_prefix}$table'

		$query = $this->write_query("
SHOW TABLES
LIKE '{$this->table_prefix}$table'

		");
$exists = $this->num_rows($query);
$this->error_reporting = $err;
if($exists > 0)
{
return true;
}
else
{
return false;
}
}


		");
$exists = $this->num_rows($query);
$this->error_reporting = $err;
if($exists > 0)
{
return true;
}
else
{
return false;
}
}


	/**
* Check if a field exists in a database.
*

	/**
* Check if a field exists in a database.
*

Zeile 691Zeile 699
			{
$query .= " ".my_strtoupper($options['order_dir']);
}

			{
$query .= " ".my_strtoupper($options['order_dir']);
}

		}

		}

		if(isset($options['limit_start']) && isset($options['limit']))

		if(isset($options['limit_start']) && isset($options['limit']))

		{

		{

			$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

			$query .= " LIMIT ".$options['limit_start'].", ".$options['limit'];

		}

		}

		elseif(isset($options['limit']))
{
$query .= " LIMIT ".$options['limit'];

		elseif(isset($options['limit']))
{
$query .= " LIMIT ".$options['limit'];

Zeile 705Zeile 713
	
/**
* Build an insert query from an array.

	
/**
* Build an insert query from an array.

	 *

	 *

	 * @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return int The insert ID if available

	 * @param string The table name to perform the query on.
* @param array An array of fields and their values.
* @return int The insert ID if available

Zeile 734Zeile 742
	 * @return int The insert ID if available
*/
function insert_query_multiple($table, $array)

	 * @return int The insert ID if available
*/
function insert_query_multiple($table, $array)

	{

	{

		if(!is_array($array))
{
return false;

		if(!is_array($array))
{
return false;

Zeile 762Zeile 770
	 *
* @param string The table name to perform the query on.
* @param array An array of fields and their values.

	 *
* @param string The table name to perform the query on.
* @param array An array of fields and their values.

	 * @param string An optional where clause for the query.

	 * @param string An optional where clause for the query.

	 * @param string An optional limit clause for the query.
* @return resource The query data.
*/

	 * @param string An optional limit clause for the query.
* @return resource The query data.
*/

Zeile 776Zeile 784
		$comma = "";
$query = "";
$quote = "'";

		$comma = "";
$query = "";
$quote = "'";

		

		

		if($no_quote == true)

		if($no_quote == true)

		{

		{

			$quote = "";

			$quote = "";

		}

		}

		
foreach($array as $field => $value)

		
foreach($array as $field => $value)

		{

		{

			$query .= $comma."`".$field."`={$quote}{$value}{$quote}";
$comma = ", ";
}


			$query .= $comma."`".$field."`={$quote}{$value}{$quote}";
$comma = ", ";
}


		if(!empty($where))
{
$query .= " WHERE $where";
}


		if(!empty($where))
{
$query .= " WHERE $where";
}


		if(!empty($limit))
{
$query .= " LIMIT $limit";

		if(!empty($limit))
{
$query .= " LIMIT $limit";

Zeile 818Zeile 826
		if(!empty($where))
{
$query .= " WHERE $where";

		if(!empty($where))
{
$query .= " WHERE $where";

		}


		}


		if(!empty($limit))
{
$query .= " LIMIT $limit";

		if(!empty($limit))
{
$query .= " LIMIT $limit";

Zeile 830Zeile 838
			FROM {$this->table_prefix}$table 
$query
");

			FROM {$this->table_prefix}$table 
$query
");

	}

/**

	}

/**


* Escape a string according to the MySQL escape format.
*


* Escape a string according to the MySQL escape format.
*

Zeile 846Zeile 854
			$string = mysql_real_escape_string($string, $this->read_link);
}
else

			$string = mysql_real_escape_string($string, $this->read_link);
}
else

		{

		{

			$string = addslashes($string);
}
return $string;

			$string = addslashes($string);
}
return $string;

Zeile 872Zeile 880
	function escape_string_like($string)
{
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));

	function escape_string_like($string)
{
return $this->escape_string(str_replace(array('%', '_') , array('\\%' , '\\_') , $string));

	}

/**

	}

/**

	 * Gets the current version of MySQL.
*
* @return string Version of MySQL.

	 * Gets the current version of MySQL.
*
* @return string Version of MySQL.

Zeile 930Zeile 938

/**
* Show the "show fields from" command for a specific table.


/**
* Show the "show fields from" command for a specific table.

	 *

	 *

	 * @param string The name of the table.
* @return string Field info for that table
*/

	 * @param string The name of the table.
* @return string Field info for that table
*/

Zeile 942Zeile 950
			$field_info[] = $field;
}
return $field_info;

			$field_info[] = $field;
}
return $field_info;

	}

/**

	}

/**

	 * Returns whether or not the table contains a fulltext index.
*
* @param string The name of the table.

	 * Returns whether or not the table contains a fulltext index.
*
* @param string The name of the table.

Zeile 966Zeile 974
			}
}
if(preg_match('#FULLTEXT KEY#i', $structure))

			}
}
if(preg_match('#FULLTEXT KEY#i', $structure))

		{
return true;
}
return false;
}

/**

		{
return true;
}
return false;
}

/**

	 * Returns whether or not this database engine supports fulltext indexing.
*
* @param string The table to be checked.

	 * Returns whether or not this database engine supports fulltext indexing.
*
* @param string The table to be checked.

Zeile 1010Zeile 1018
		$version = $this->get_version();
$supports_fulltext = $this->supports_fulltext($table);
if($version >= '4.0.1' && $supports_fulltext == true)

		$version = $this->get_version();
$supports_fulltext = $this->supports_fulltext($table);
if($version >= '4.0.1' && $supports_fulltext == true)

		{
return true;
}
return false;
}
















		{
return true;
}
return false;
}

/**
* Creates a fulltext index on the specified column in the specified table with optional index name.
*
* @param string The name of the table.
* @param string Name of the column to be indexed.
* @param string The index name, optional.
*/
function create_fulltext_index($table, $column, $name="")
{
$this->write_query("
ALTER TABLE {$this->table_prefix}$table
ADD FULLTEXT $name ($column)
");
}


/**


/**

	 * Creates a fulltext index on the specified column in the specified table with optional index name.

	 * Drop an index with the specified name from the specified table

	 *
* @param string The name of the table.

	 *
* @param string The name of the table.

	 * @param string Name of the column to be indexed.
* @param string The index name, optional.

	 * @param string The name of the index.


	 */

	 */

	function create_fulltext_index($table, $column, $name="")

	function drop_index($table, $name)

	{
$this->write_query("
ALTER TABLE {$this->table_prefix}$table

	{
$this->write_query("
ALTER TABLE {$this->table_prefix}$table

			ADD FULLTEXT $name ($column)

			DROP INDEX $name

		");
}

		");
}



	

	/**

	/**

	 * Drop an index with the specified name from the specified table

	 * Checks to see if an index exists on a specified table

	 *
* @param string The name of the table.
* @param string The name of the index.
*/

	 *
* @param string The name of the table.
* @param string The name of the index.
*/

	function drop_index($table, $name)

	function index_exists($table, $index)

	{

	{

		$this->write_query("
ALTER TABLE {$this->table_prefix}$table
DROP INDEX $name
");














		$index_exists = false;
$query = $this->write_query("SHOW INDEX FROM {$this->table_prefix}{$table}");
while($ukey = $this->fetch_array($query))
{
if($ukey['Key_name'] == $index)
{
$index_exists = true;
break;
}
}

if($index_exists)
{
return true;
}

return false;

	}

/**

	}

/**

Zeile 1138Zeile 1173
	 */
function fetch_db_charsets()
{

	 */
function fetch_db_charsets()
{

		if($this_link && $this->get_version() < 4.1)

		if($this->link && version_compare($this->get_version(), "4.1", "<"))

		{
return false;
}

		{
return false;
}