[HyperDB] HyperDB and strange characters

Colin Ogilvie cogilvie at plus.net
Wed Jun 25 13:31:50 GMT 2008


Andy Skelton wrote:
> My solution is to do mysql_query( SET NAMES... ) immediately after
> successful mysql_connect in the db_connect method. Try that and let me
> know whether it works for you.

Yep, that seems to have worked for me.

I've attached the patch I used to this email (it also includes another 
change to the query log just to include the hostname too :))

Colin

-- 
| Colin Ogilvie                                 Broadband Solutions for
| Web Developer                                     Home and Business @
| PlusNet PLC                                              www.plus.net
| Registered Office: Internet House, 2 Tenter Street, Sheffield, S1 4BY
| Registered in England no: 3279013
+ ------------ PlusNet - The smarter way to broadband ----------------+

-------------- next part --------------
Index: db.php
===================================================================
--- db.php	(revision 51737)
+++ db.php	(working copy)
@@ -57,14 +57,9 @@
 
 	function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
 		register_shutdown_function(array(&$this, "__destruct"));
-
 		if ( defined('WP_DEBUG') and WP_DEBUG == true )
 			$this->show_errors();
 
-		if( defined( "WP_USE_MULTIPLE_DB" ) && CONSTANT( "WP_USE_MULTIPLE_DB" ) == true ) {
-			$this->multiple_db = true;
-			return true;
-		}
 
 		if ( defined('DB_CHARSET') )
 			$this->charset = DB_CHARSET;
@@ -72,6 +67,11 @@
 		if ( defined('DB_COLLATE') )
 			$this->collate = DB_COLLATE;
 
+		if( defined( "WP_USE_MULTIPLE_DB" ) && CONSTANT( "WP_USE_MULTIPLE_DB" ) == true ) {
+			$this->multiple_db = true;
+			return true;
+		}
+
 		$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
 		if (!$this->dbh) {
 			$this->print_error( "Can't connect " . $dbhost );
@@ -473,11 +473,11 @@
 			} else {
 				$this->$dbhname = false;
 			}
-
 			$this->connections[] = "{$server['user']}@$host";
 
 			if ( $this->$dbhname && is_resource($this->$dbhname) )  {
 				$current_connection .= " connected to $host in " . number_format( ( $this->timer_stop() * 1000 ), 2) . 'ms';
+				@mysql_query("SET NAMES '$this->charset'", $this->$dbhname);
 				$this->connection_array[] = array( $host, number_format( ( $this->timer_stop() ), 7) );
 				$this->current_host = $host;
 				$this->open_connections[] = $dbhname;
@@ -580,7 +580,7 @@
 		++$this->num_queries;
 
 		if (SAVEQUERIES)
-			$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
+			$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller(), $this->current_host );
 
 		// If there is an error then take note of it
 		if ( $this->last_error = mysql_error($this->dbh) ) {
@@ -921,4 +921,4 @@
 
 if ( ! isset($wpdb) )
 	$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
-?>
\ No newline at end of file
+?>


More information about the HyperDB mailing list