<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: MySQL Prepared Statements from PHP: MySQLi vs PDO</title>
	<atom:link href="http://www.robpoyntz.com/blog/?feed=rss2&#038;p=260" rel="self" type="application/rss+xml" />
	<link>http://www.robpoyntz.com/blog/?p=260</link>
	<description>Learning how to write software and trying to stand on a surfboard</description>
	<lastBuildDate>Mon, 06 Sep 2010 12:02:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: lulu</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5880</link>
		<dc:creator>lulu</dc:creator>
		<pubDate>Wed, 17 Mar 2010 07:11:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5880</guid>
		<description>Thank you for quick answer and best code.</description>
		<content:encoded><![CDATA[<p>Thank you for quick answer and best code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRP</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5879</link>
		<dc:creator>RRP</dc:creator>
		<pubDate>Wed, 17 Mar 2010 06:06:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5879</guid>
		<description>Hi Lulu,

There are a few major differences in the new code:

1) The API has changed - for example instead of (while $obj = $db-&gt;Fetch()) from the old code, EasyPDO uses foreach ($db-&gt;Fetch() as $idx =&gt; $obj).
2) The new code does not support PHP&#039;s MySQLi drivers - mainly because PDO/MySQL is quicker
3) EasyPDO supports more database engines, currently MySQL, PostGres and SQLite

If the old code is working for you, then there&#039;s no need to change!</description>
		<content:encoded><![CDATA[<p>Hi Lulu,</p>
<p>There are a few major differences in the new code:</p>
<p>1) The API has changed &#8211; for example instead of (while $obj = $db-&gt;Fetch()) from the old code, EasyPDO uses foreach ($db-&gt;Fetch() as $idx =&gt; $obj).<br />
2) The new code does not support PHP&#8217;s MySQLi drivers &#8211; mainly because PDO/MySQL is quicker<br />
3) EasyPDO supports more database engines, currently MySQL, PostGres and SQLite</p>
<p>If the old code is working for you, then there&#8217;s no need to change!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lulu</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5878</link>
		<dc:creator>lulu</dc:creator>
		<pubDate>Wed, 17 Mar 2010 05:56:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5878</guid>
		<description>What different EasyPDO and old code ? I&#039;m will change my code. But i&#039;m think old code is well work for me. It&#039;s great.</description>
		<content:encoded><![CDATA[<p>What different EasyPDO and old code ? I&#8217;m will change my code. But i&#8217;m think old code is well work for me. It&#8217;s great.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRP</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5843</link>
		<dc:creator>RRP</dc:creator>
		<pubDate>Mon, 15 Mar 2010 08:21:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5843</guid>
		<description>T,

Please check out http://easypdo.robpoyntz.com - latest version which should have ironed out most of those issues.

Cheers,
RRP</description>
		<content:encoded><![CDATA[<p>T,</p>
<p>Please check out <a href="http://easypdo.robpoyntz.com" rel="nofollow">http://easypdo.robpoyntz.com</a> &#8211; latest version which should have ironed out most of those issues.</p>
<p>Cheers,<br />
RRP</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRP</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5838</link>
		<dc:creator>RRP</dc:creator>
		<pubDate>Sun, 14 Mar 2010 11:58:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5838</guid>
		<description>Hi T,

It looks like there could well be a few problems in that code. If you can please bear with me for another day or so, I&#039;m about to release a new version (and a new site to go with it). The current version is really just a private project, and that parts of the code I don&#039;t use myself aren&#039;t well tested. The new version will be fully tested, supported, and released under a sensible license.</description>
		<content:encoded><![CDATA[<p>Hi T,</p>
<p>It looks like there could well be a few problems in that code. If you can please bear with me for another day or so, I&#8217;m about to release a new version (and a new site to go with it). The current version is really just a private project, and that parts of the code I don&#8217;t use myself aren&#8217;t well tested. The new version will be fully tested, supported, and released under a sensible license.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5808</link>
		<dc:creator>T</dc:creator>
		<pubDate>Fri, 12 Mar 2010 14:01:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5808</guid>
		<description>The query is simple: &quot;SELECT * FROM `users`&quot;
I didn&#039;t even use any parameters, and when I try something like &quot;SELECT * FROM `users` WHERE 1=?&quot; and pass 1 as the parameter, it still doesn&#039;t work. Table definition is simple, something along the lines of:

Table `users`:

users_ID &#124; Username &#124; Created &#124; LastModified

There are a few lines in the source code of your class that might be causing the problem. Namely, these lines of FetchRowAssoc:
      
      if ($query = $this-&gt;MySQLi-&gt;prepare($sql))
        throw new EDatabaseException($this-&gt;MySQLi-&gt;error);

Appear to be related to these lines in FetchRow:

      if (!$query = $this-&gt;MySQLi-&gt;prepare($sql))
        throw new EDatabaseException($this-&gt;MySQLi-&gt;error);

However, there is no not operator in the FetchRowAssoc implementation. Should there be? Also, in FetchRow:

if ($this-&gt;MySQLi-&gt;errno != 0) throw new EDatabaseException($this-&gt;MySQLi-&gt;error);

That line appears related to this line in FetchRowAssoc:

if ($this-&gt;errno != 0) throw new EDatabaseException($this-&gt;error);

But in the FetchRowAssoc version, $this-&gt;[property] is used instead of $this-&gt;MySQLi-&gt;[property]. 

I changed those two things in FetchRowAssoc and everything worked up to these lines where it failed:

if (!call_user_func_array(array($this-&gt;Query, &#039;bind_result&#039;), $bindparams))
        throw new EDatabaseException(&#039;Bind parameters failed&#039;);

It was either those lines, or the other two lines that binded parameters.</description>
		<content:encoded><![CDATA[<p>The query is simple: &#8220;SELECT * FROM `users`&#8221;<br />
I didn&#8217;t even use any parameters, and when I try something like &#8220;SELECT * FROM `users` WHERE 1=?&#8221; and pass 1 as the parameter, it still doesn&#8217;t work. Table definition is simple, something along the lines of:</p>
<p>Table `users`:</p>
<p>users_ID | Username | Created | LastModified</p>
<p>There are a few lines in the source code of your class that might be causing the problem. Namely, these lines of FetchRowAssoc:</p>
<p>      if ($query = $this-&gt;MySQLi-&gt;prepare($sql))<br />
        throw new EDatabaseException($this-&gt;MySQLi-&gt;error);</p>
<p>Appear to be related to these lines in FetchRow:</p>
<p>      if (!$query = $this-&gt;MySQLi-&gt;prepare($sql))<br />
        throw new EDatabaseException($this-&gt;MySQLi-&gt;error);</p>
<p>However, there is no not operator in the FetchRowAssoc implementation. Should there be? Also, in FetchRow:</p>
<p>if ($this-&gt;MySQLi-&gt;errno != 0) throw new EDatabaseException($this-&gt;MySQLi-&gt;error);</p>
<p>That line appears related to this line in FetchRowAssoc:</p>
<p>if ($this-&gt;errno != 0) throw new EDatabaseException($this-&gt;error);</p>
<p>But in the FetchRowAssoc version, $this-&gt;[property] is used instead of $this-&gt;MySQLi-&gt;[property]. </p>
<p>I changed those two things in FetchRowAssoc and everything worked up to these lines where it failed:</p>
<p>if (!call_user_func_array(array($this-&gt;Query, &#8216;bind_result&#8217;), $bindparams))<br />
        throw new EDatabaseException(&#8216;Bind parameters failed&#8217;);</p>
<p>It was either those lines, or the other two lines that binded parameters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRP</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5801</link>
		<dc:creator>RRP</dc:creator>
		<pubDate>Fri, 12 Mar 2010 02:10:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5801</guid>
		<description>T,

This seems to be failing on the MySQLi-&gt;prepare($sql) line - prepare sends your query to the database engine for compilation, so if an error is occurring here it&#039;s likely that your SQL statement is invalid. What is the error code that&#039;s being reported?

If you can send me the SQL, table definition and parameters you&#039;re using, I might be able to spot the problem.</description>
		<content:encoded><![CDATA[<p>T,</p>
<p>This seems to be failing on the MySQLi->prepare($sql) line &#8211; prepare sends your query to the database engine for compilation, so if an error is occurring here it&#8217;s likely that your SQL statement is invalid. What is the error code that&#8217;s being reported?</p>
<p>If you can send me the SQL, table definition and parameters you&#8217;re using, I might be able to spot the problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5799</link>
		<dc:creator>T</dc:creator>
		<pubDate>Fri, 12 Mar 2010 01:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5799</guid>
		<description>Line 382 and 383 are failing:
     if ($query = $this-&gt;MySQLi-&gt;prepare($sql))
        throw new EDatabaseException($this-&gt;MySQLi-&gt;error);
with this generic error:

Fatal error: Uncaught exception &#039;EDatabaseException&#039; in Path\to\dbconnect.php:383 Stack trace: #0 Path\to\file.php(line#): DF_MySQLi-&gt;FetchRowAssoc(&#039;SELECT * FROM u...&#039;) #1 {main} thrown in Path\to\dbconnect.php on line 383</description>
		<content:encoded><![CDATA[<p>Line 382 and 383 are failing:<br />
     if ($query = $this-&gt;MySQLi-&gt;prepare($sql))<br />
        throw new EDatabaseException($this-&gt;MySQLi-&gt;error);<br />
with this generic error:</p>
<p>Fatal error: Uncaught exception &#8216;EDatabaseException&#8217; in Path\to\dbconnect.php:383 Stack trace: #0 Path\to\file.php(line#): DF_MySQLi-&gt;FetchRowAssoc(&#8216;SELECT * FROM u&#8230;&#8217;) #1 {main} thrown in Path\to\dbconnect.php on line 383</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: T</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5798</link>
		<dc:creator>T</dc:creator>
		<pubDate>Fri, 12 Mar 2010 01:30:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5798</guid>
		<description>Thanks so much! I wanted prepared statements but didn&#039;t want to manually bind individual variables for each result variable. Tried Doctrine, didn&#039;t like it. This helps A LOT.</description>
		<content:encoded><![CDATA[<p>Thanks so much! I wanted prepared statements but didn&#8217;t want to manually bind individual variables for each result variable. Tried Doctrine, didn&#8217;t like it. This helps A LOT.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RRP</title>
		<link>http://www.robpoyntz.com/blog/?p=260&#038;cpage=1#comment-5169</link>
		<dc:creator>RRP</dc:creator>
		<pubDate>Wed, 13 Jan 2010 12:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.robpoyntz.com/blog/?p=260#comment-5169</guid>
		<description>Hi Andrew,

New version coming soon that addresses this issue and others. Will keep you posted.</description>
		<content:encoded><![CDATA[<p>Hi Andrew,</p>
<p>New version coming soon that addresses this issue and others. Will keep you posted.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
