<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thomas Hambach - Web engineer &#187; patch</title>
	<atom:link href="http://www.rdlt.com/category/patch/feed" rel="self" type="application/rss+xml" />
	<link>http://www.rdlt.com</link>
	<description>Web development, Web design &#38; Usability</description>
	<lastBuildDate>Mon, 06 Dec 2010 09:45:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>mysqli for WordPress 2.9.1</title>
		<link>http://www.rdlt.com/mysqli-for-wordpress-2-9-1.html</link>
		<comments>http://www.rdlt.com/mysqli-for-wordpress-2-9-1.html#comments</comments>
		<pubDate>Thu, 07 Jan 2010 15:18:22 +0000</pubDate>
		<dc:creator>Thomas Hambach</dc:creator>
				<category><![CDATA[freebies]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.rdlt.com/?p=271</guid>
		<description><![CDATA[WordPress does not officialy support the mysqli drivers. I needed my WordPress installation to use the mysqli class instead of the mysql ones. I&#8217;m sure there will be someone else out there with the same needs I decided to place the modified database class and the patch file online. Use whichever you prefer. Full: Download [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-thumbnail wp-image-256" title="wordpress-logo" src="http://www.rdlt.com/wp-content/uploads/2009/12/wordpress-logo-150x150.png" alt="wordpress-logo" width="150" height="150" />WordPress does not officialy support the <a href="http://be2.php.net/manual/en/class.mysqli.php" target="_blank">mysqli</a> drivers.  I needed my WordPress installation to use the mysqli class instead of the mysql ones. I&#8217;m sure there will be someone else out there with the same needs I decided to place the modified database class and the patch file online. Use whichever you prefer.</p>
<ul>
<li><strong>Full:</strong> <a href="http://www.rdlt.com/wp-content/uploads/2010/01/wp-db-2.9.1-class.zip" target="_blank">Download WordPress 2.9.1 mysqli database class</a></li>
<li><strong>Patch: </strong><a href="http://www.rdlt.com/wp-content/uploads/2010/01/wp-db-2.9.1-patch.zip" target="_blank">Download WordPress 2.9.1 mysqli database class</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.rdlt.com/mysqli-for-wordpress-2-9-1.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress mysqli 2.9 Database Class Patch</title>
		<link>http://www.rdlt.com/wordpress-mysqli-2-9-database-class-patch.html</link>
		<comments>http://www.rdlt.com/wordpress-mysqli-2-9-database-class-patch.html#comments</comments>
		<pubDate>Wed, 30 Dec 2009 10:30:51 +0000</pubDate>
		<dc:creator>Thomas Hambach</dc:creator>
				<category><![CDATA[freebies]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.rdlt.com/?p=253</guid>
		<description><![CDATA[WordPress does not officialy support the mysqli drivers.  I needed my WordPress installation to use the mysqli class instead of the mysql ones. I&#8217;m sure there will be someone else out there with the same needs I decided to place the modified database class and the patch file online. Use whichever you prefer. Full: Download [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-thumbnail wp-image-256" title="wordpress-logo" src="http://www.rdlt.com/wp-content/uploads/2009/12/wordpress-logo-150x150.png" alt="wordpress-logo" width="150" height="150" />WordPress does not officialy support the <a href="http://be2.php.net/manual/en/class.mysqli.php" target="_blank">mysqli</a> drivers.  I needed my WordPress installation to use the mysqli class instead of the mysql ones. I&#8217;m sure there will be someone else out there with the same needs I decided to place the modified database class and the patch file online. Use whichever you prefer.</p>
<ul>
<li><strong>Full:</strong> <a href="http://www.rdlt.com/wp-content/uploads/2009/12/wp-db-2.9-class.zip" target="_blank">Download WordPress 2.9 mysqli database class</a></li>
<li><strong>Patch: </strong><a href="http://www.rdlt.com/wp-content/uploads/2009/12/wp-db-2.9-patch.zip" target="_blank">Download WordPress 2.9 mysqli database class</a></li>
</ul>
<p><span id="more-253"></span></p>
<h3>Patch contents</h3>
<pre><code>Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 19)
+++ wp-includes/wp-db.php	(working copy)
@@ -367,9 +367,12 @@
 			$this-&gt;collate = DB_COLLATE;

 		$this-&gt;dbuser = $dbuser;
+
+		// $this-&gt;dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
+		$this-&gt;dbh = new mysqli($dbhost, $dbuser, $dbpassword, $dbname); 

-		$this-&gt;dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
-		if (!$this-&gt;dbh) {
+		// if (!$this-&gt;dbh) {
+		if ($this-&gt;dbh-&gt;connect_error || mysqli_connect_error()) { // remember $mysqli-&gt;connect_error is broken in PHP &lt; 5.2.9
 			$this-&gt;bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/"
 &lt;h1&gt;Error establishing a database connection&lt;/h1&gt;
 &lt;p&gt;This either means that the username and password information in your &lt;code&gt;wp-config.php&lt;/code&gt; file is incorrect or we can't contact the database server at &lt;code&gt;%s&lt;/code&gt;. This could mean your host's database server is down.&lt;/p&gt;
@@ -386,18 +389,21 @@
 		$this-&gt;ready = true;

 		if ( !empty($this-&gt;charset) ) {
+			$this-&gt;dbh-&gt;set_charset($this-&gt;charset);
+			$this-&gt;real_escape = true;
+			/*
 			if ( function_exists('mysql_set_charset') ) {
 				mysql_set_charset($this-&gt;charset, $this-&gt;dbh);
-				$this-&gt;real_escape = true;
 			} else {
 				$collation_query = "SET NAMES '{$this-&gt;charset}'";
 				if ( !empty($this-&gt;collate) )
 					$collation_query .= " COLLATE '{$this-&gt;collate}'";
 				$this-&gt;query($collation_query);
-			}
+			}*/
 		}

-		$this-&gt;select($dbname);
+		// selection of database with mysql happens when connecting
+		// $this-&gt;select($dbname);
 	}

 	/**
@@ -454,6 +460,9 @@
 	 * @return null Always null.
 	 */
 	function select($db) {
+
+		return true; // database selection happens in constructor when usng mysqli
+
 		if (!@mysql_select_db($db, $this-&gt;dbh)) {
 			$this-&gt;ready = false;
 			$this-&gt;bail(sprintf(/*WP_I18N_DB_SELECT_DB*/'
@@ -475,7 +484,7 @@

 	function _real_escape($string) {
 		if ( $this-&gt;dbh &#038;&#038; $this-&gt;real_escape )
-			return mysql_real_escape_string( $string, $this-&gt;dbh );
+			return $this-&gt;dbh-&gt;real_escape_string( $string );
 		else
 			return addslashes( $string );
 	}
@@ -579,7 +588,7 @@
 	function print_error($str = '') {
 		global $EZSQL_ERROR;

-		if (!$str) $str = mysql_error($this-&gt;dbh);
+		if (!$str) $str = $this-&gt;dbh-&gt;error;
 		$EZSQL_ERROR[] = array ('query' =&gt; $this-&gt;last_query, 'error_str' =&gt; $str);

 		if ( $this-&gt;suppress_errors )
@@ -703,39 +712,40 @@
 		if ( defined('SAVEQUERIES') &#038;&#038; SAVEQUERIES )
 			$this-&gt;timer_start();

-		$this-&gt;result = @mysql_query($query, $this-&gt;dbh);
+		$this-&gt;result = $this-&gt;dbh-&gt;query($query);
 		++$this-&gt;num_queries;

 		if ( defined('SAVEQUERIES') &#038;&#038; SAVEQUERIES )
 			$this-&gt;queries[] = array( $query, $this-&gt;timer_stop(), $this-&gt;get_caller() );

 		// If there is an error then take note of it..
-		if ( $this-&gt;last_error = mysql_error($this-&gt;dbh) ) {
+		if ( $this-&gt;last_error = $this-&gt;dbh-&gt;error) {
 			$this-&gt;print_error();
 			return false;
 		}

 		if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {
-			$this-&gt;rows_affected = mysql_affected_rows($this-&gt;dbh);
+			$this-&gt;rows_affected = $this-&gt;db-&gt;affected_rows;
 			// Take note of the insert_id
 			if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
-				$this-&gt;insert_id = mysql_insert_id($this-&gt;dbh);
+				$this-&gt;insert_id = $this-&gt;db-&gt;insert_id;
 			}
 			// Return number of rows affected
 			$return_val = $this-&gt;rows_affected;
 		} else {
 			$i = 0;
-			while ($i &lt; @mysql_num_fields($this-&gt;result)) {
-				$this-&gt;col_info[$i] = @mysql_fetch_field($this-&gt;result);
+			while ($i &lt; $this-&gt;result-&gt;field_count) {
+				$this-&gt;col_info[$i] = @$this-&gt;result-&gt;fetch_field();
 				$i++;
 			}
 			$num_rows = 0;
-			while ( $row = @mysql_fetch_object($this-&gt;result) ) {
+			while ( $row = @$this-&gt;result-&gt;fetch_object() ) {
 				$this-&gt;last_result[$num_rows] = $row;
 				$num_rows++;
 			}

-			@mysql_free_result($this-&gt;result);
+			// no more need for freeing results, they ARE free! <img src='http://www.rdlt.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />
+			// @mysql_free_result($this-&gt;result);

 			// Log number of rows the query returned
 			$this-&gt;num_rows = $num_rows;
@@ -1138,4 +1148,5 @@
 	 */
 	$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
 }
+
 ?&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rdlt.com/wordpress-mysqli-2-9-database-class-patch.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

