← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1699: [database] Use proper way to set MYSQLi charset; fix docs

 

------------------------------------------------------------
revno: 1699
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Tue 2009-07-21 20:22:09 +0200
message:
  [database] Use proper way to set MYSQLi charset; fix docs
  
  ...and issue SET NAMES as a fallback mechanism only. Also
  fixed some wrong references in the API docs.
modified:
  database/backend-mysql.lib.php
  database/connection.lib.php

=== modified file 'database/backend-mysql.lib.php'
--- database/backend-mysql.lib.php	2009-07-20 20:41:56 +0000
+++ database/backend-mysql.lib.php	2009-07-21 18:22:09 +0000
@@ -60,31 +60,42 @@
 		$database = $this->settings['database'];
 		$encoding = $this->settings['encoding'];
 
+
 		/* Persistent connection are only available since PHP 5.3 */
+
 		if (version_compare(PHP_VERSION, '5.3.0', '>='))
 			$hostname = sprintf('p:%s', $hostname);
 
+
+		/* Create the connection */
+
 		try
 		{
-			$this->connection_handle = @new MySQLi($hostname, $username, $password, $database);
+			$this->connection_handle = new MySQLi($hostname, $username, $password, $database);
 		}
 		catch (Exception $e)
 		{
 			throw new AnewtDatabaseConnectionException('Could not connect to MySQL database: %s', $e->getMessage());
 		}
 
+
+		/* Set the encoding */
+
 		if ($encoding)
 		{
 			try
 			{
-				$this->prepare_execute('SET NAMES ?str?', $encoding);
+				$charset_success = $this->connection_handle->set_charset($encoding);
+
+				/* Issue SET NAMES query as a fallback only */
+				if (!$charset_success)
+					$this->prepare_execute('SET NAMES ?str?', $encoding);
 			}
 			catch (Exception $e)
 			{
 				throw new AnewtDatabaseConnectionException('Could not set MySQL encoding to "%s": %s', $encoding, $e->getMessage());
 			}
 		}
-
 	}
 
 	protected function real_disconnect()

=== modified file 'database/connection.lib.php'
--- database/connection.lib.php	2009-07-20 20:41:56 +0000
+++ database/connection.lib.php	2009-07-21 18:22:09 +0000
@@ -212,9 +212,9 @@
 	 * \return
 	 *   The number of rows affected by the query.
 	 *
-	 * \see DB::prepare_execute
-	 * \see DB::prepare_executev_fetch_one
-	 * \see DB::prepare_executev_fetch_all
+	 * \see AnewtDatabaseConnection::prepare_execute
+	 * \see AnewtDatabaseConnection::prepare_executev_fetch_one
+	 * \see AnewtDatabaseConnection::prepare_executev_fetch_all
 	 */
 	public function prepare_executev($sql, $values=null)
 	{
@@ -251,9 +251,9 @@
 	 * \param $values  Zero or more values to be substituted for the placeholders
 	 * \return         A single row, or \c NULL
 	 *
-	 * \see DB::prepare_executev_fetch_one
-	 * \see DB::prepare_execute
-	 * \see DB::prepare_execute_fetch_all
+	 * \see AnewtDatabaseConnection::prepare_executev_fetch_one
+	 * \see AnewtDatabaseConnection::prepare_execute
+	 * \see AnewtDatabaseConnection::prepare_execute_fetch_all
 	 */
 	public function prepare_execute_fetch_one($sql, $values=null)
 	{
@@ -271,9 +271,9 @@
 	 * \param $values  Zero or more values to be substituted for the placeholders
 	 * \return         A single row, or \c NULL
 	 *
-	 * \see DB::prepare_execute_fetch_one
-	 * \see DB::prepare_executev
-	 * \see DB::prepare_executev_fetch_all
+	 * \see AnewtDatabaseConnection::prepare_execute_fetch_one
+	 * \see AnewtDatabaseConnection::prepare_executev
+	 * \see AnewtDatabaseConnection::prepare_executev_fetch_all
 	 */
 	public function prepare_executev_fetch_one($sql, $values=null)
 	{
@@ -292,9 +292,9 @@
 	 * \param $values  Zero or more values to be substituted for the placeholders
 	 * \return         Array of all rows (may be empty)
 	 *
-	 * \see DB::prepare_executev_fetch_all
-	 * \see DB::prepare_execute
-	 * \see DB::prepare_execute_fetch_one
+	 * \see AnewtDatabaseConnection::prepare_executev_fetch_all
+	 * \see AnewtDatabaseConnection::prepare_execute
+	 * \see AnewtDatabaseConnection::prepare_execute_fetch_one
 	 */
 	public function prepare_execute_fetch_all($sql, $values=null)
 	{
@@ -312,9 +312,9 @@
 	 * \param $values  Zero or more values to be substituted for the placeholders
 	 * \return         Array of all rows (may be empty)
 	 *
-	 * \see DB::prepare_execute_fetch_all
-	 * \see DB::prepare_executev
-	 * \see DB::prepare_executev_fetch_one
+	 * \see AnewtDatabaseConnection::prepare_execute_fetch_all
+	 * \see AnewtDatabaseConnection::prepare_executev
+	 * \see AnewtDatabaseConnection::prepare_executev_fetch_one
 	 */
 	public function prepare_executev_fetch_all($sql, $values=null)
 	{
@@ -380,6 +380,9 @@
 	 * Execute SQL and create an AnewtDatabaseResultSet for a query.
 	 * 
 	 * This method is for internal use only and is backend-specific.
+	 *
+	 * \param $sql
+	 *   The SQL query to execute.
 	 */
 	abstract protected function real_execute_sql($sql);
 



--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.