<?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: MySQLi Vs PDO</title>
	<atom:link href="http://jacobsantos.com/2006/general/mysqli-vs-pdo/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/</link>
	<description>Rumblings, rants, essays, stories by Jacob Santos about Web Site Development, Persistent Browser-Based Games, personal journal, and Programming.</description>
	<lastBuildDate>Mon, 01 Feb 2010 19:53:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jacob Santos</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-33323</link>
		<dc:creator>Jacob Santos</dc:creator>
		<pubDate>Fri, 08 Aug 2008 23:02:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-33323</guid>
		<description>@Terence Chang,

Not really, ADODB can use PDO in order to access the databases. PDO is more abstraction of various database APIs, so that you don&#039;t have to change the functions everywhere. It doesn&#039;t abstract the SQL and rewrite it for you like some other Database and SQL abstraction libraries out there.

The query() function uses prepare() in its implementation. You want to turn on Emulate_Prepares for mysql when using it. That might change when the PDO_MYSQLND driver comes out.

I use PDO, because it has less overhead and it does what I need it too. ADODB is implemented in PHP (mostly, there is a PHP extension to speed it up) and PDO is implemented in C. For most of my projects I haven&#039;t needed the power of ADODB and I&#039;m comfortable with PDO after using it for a number of years.

Really, most of my queries are prepared statements, even if I&#039;m making one query at a time, I usually save the prepared object as a static property of the class I&#039;m working in to be used later. I haven&#039;t done any benchmarks to know if it actually is any faster.</description>
		<content:encoded><![CDATA[<p>@Terence Chang,</p>
<p>Not really, ADODB can use PDO in order to access the databases. PDO is more abstraction of various database APIs, so that you don&#8217;t have to change the functions everywhere. It doesn&#8217;t abstract the SQL and rewrite it for you like some other Database and SQL abstraction libraries out there.</p>
<p>The query() function uses prepare() in its implementation. You want to turn on Emulate_Prepares for mysql when using it. That might change when the PDO_MYSQLND driver comes out.</p>
<p>I use PDO, because it has less overhead and it does what I need it too. ADODB is implemented in PHP (mostly, there is a PHP extension to speed it up) and PDO is implemented in C. For most of my projects I haven&#8217;t needed the power of ADODB and I&#8217;m comfortable with PDO after using it for a number of years.</p>
<p>Really, most of my queries are prepared statements, even if I&#8217;m making one query at a time, I usually save the prepared object as a static property of the class I&#8217;m working in to be used later. I haven&#8217;t done any benchmarks to know if it actually is any faster.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Terence Chang</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-33313</link>
		<dc:creator>Terence Chang</dc:creator>
		<pubDate>Thu, 07 Aug 2008 19:52:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-33313</guid>
		<description>Hi Jacob:

I think I saw you somewhere. Anway. Is ADODB out of picture in the case? 

I used to use PHP ADODB library and switch database between MySQL and MSSQL. I think PDO may fit my need to convert MySQL into Oracle later on PHP5.2.6+. 

I have heard people saying that prepare() function may not use the true MysQL Cache feature on MYSQL server. People recommend to use query() for statement that need to be cached. 

Ex. 

select SQL_CACHE firstname, lastname from table ... 

I have never use prepare() with stored procedure to pass in and pass out the record sets. I heard that PDO did not do good job on passing multiple records sets from MSSQL. 

Can you really recommend to use PDO for the following reasons, or should I go back to ADODB? I think MYSQLi won&#039;t get me anywhere. 

1. Support different databases
2. Performance with cache (a lot of huge tables need to be cached)
3. Support stored procedures with parameters in and out. 

Thank you so much! I am glad that I found your blog.</description>
		<content:encoded><![CDATA[<p>Hi Jacob:</p>
<p>I think I saw you somewhere. Anway. Is ADODB out of picture in the case? </p>
<p>I used to use PHP ADODB library and switch database between MySQL and MSSQL. I think PDO may fit my need to convert MySQL into Oracle later on PHP5.2.6+. </p>
<p>I have heard people saying that prepare() function may not use the true MysQL Cache feature on MYSQL server. People recommend to use query() for statement that need to be cached. </p>
<p>Ex. </p>
<p>select SQL_CACHE firstname, lastname from table &#8230; </p>
<p>I have never use prepare() with stored procedure to pass in and pass out the record sets. I heard that PDO did not do good job on passing multiple records sets from MSSQL. </p>
<p>Can you really recommend to use PDO for the following reasons, or should I go back to ADODB? I think MYSQLi won&#8217;t get me anywhere. </p>
<p>1. Support different databases<br />
2. Performance with cache (a lot of huge tables need to be cached)<br />
3. Support stored procedures with parameters in and out. </p>
<p>Thank you so much! I am glad that I found your blog.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Santos</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-33301</link>
		<dc:creator>Jacob Santos</dc:creator>
		<pubDate>Tue, 05 Aug 2008 01:57:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-33301</guid>
		<description>@John

It actually is pretty easy once you get used to the API. Speed can be fine, but more robust? Maybe not. Depends on your needs.</description>
		<content:encoded><![CDATA[<p>@John</p>
<p>It actually is pretty easy once you get used to the API. Speed can be fine, but more robust? Maybe not. Depends on your needs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Bubriski</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-33299</link>
		<dc:creator>John Bubriski</dc:creator>
		<pubDate>Mon, 04 Aug 2008 19:05:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-33299</guid>
		<description>I just started using MySQLI.  I have no need for additional databases, but does PDO have any other benefits over MySQLI?

Speed?
Ease of Use? (doesn&#039;t sound like it!)
More Robust?</description>
		<content:encoded><![CDATA[<p>I just started using MySQLI.  I have no need for additional databases, but does PDO have any other benefits over MySQLI?</p>
<p>Speed?<br />
Ease of Use? (doesn&#8217;t sound like it!)<br />
More Robust?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Santos</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-31009</link>
		<dc:creator>Jacob Santos</dc:creator>
		<pubDate>Fri, 18 Jan 2008 02:24:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-31009</guid>
		<description>That is a very good idea, Mario. I was thinking of doing that, but was unsure if it would work.</description>
		<content:encoded><![CDATA[<p>That is a very good idea, Mario. I was thinking of doing that, but was unsure if it would work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mario</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-30998</link>
		<dc:creator>Mario</dc:creator>
		<pubDate>Thu, 17 Jan 2008 19:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-30998</guid>
		<description>For chigging, you can always use call_user_func_array() if you don&#039;t want to type each individual parameters.

[php]
$a[0] = &#039;ss&#039;;
$a[1] = &#039;test1&#039;;
$a[2] = &#039;test2&#039;;
call_user_func_array(array($stmt, &#039;bind_params&#039;), $array);
[/php]</description>
		<content:encoded><![CDATA[<p>For chigging, you can always use call_user_func_array() if you don&#8217;t want to type each individual parameters.</p>
<pre class="brush: php;">
$a[0] = 'ss';
$a[1] = 'test1';
$a[2] = 'test2';
call_user_func_array(array($stmt, 'bind_params'), $array);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: chiggins</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-12404</link>
		<dc:creator>chiggins</dc:creator>
		<pubDate>Fri, 20 Jul 2007 18:41:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-12404</guid>
		<description>Here&#039;s a good reason to like PDO and hate the MYSQLi.

Let&#039;s say that you&#039;re making a mapper class. And in the mapper class, you&#039;re trying to create an &quot;insert($objects)&quot; method that can go get the relevant fields from the object, and insert them.

The way I tried to do it was to count up the fields, use that to make a string of &quot;?,?,?&quot; placeholders, and then pass the array of values into execute(). That works in PDO, the way it does in Perl DBI.

But not with mysqli. As far as I can tell, with mysqli, you prepare the statement, and then you have to bind them explicitly like so:

  $stmt-&gt;bind_params(&quot;sss&quot;, $foo, $bar, $baz);

Whatever, seems like BS to me. But more importantly, if I&#039;m passing in an array with an arbitrary number of insert values:

1. now I have to do some kind of meta-info about each object attribute? so i can create that string? Bullocks.
2. as far as i know, correct me if I&#039;m wrong, I can&#039;t just do $stmt-&gt;bind_params(&quot;sss&quot;, @attrs), they have to be broken out into individual variables. Again, bad bad bad. If this was Perl, it wouldn&#039;t care if I passed in a list of vars or an array. But in PHP, it&#039;s much easier to put things into an param array than to bust individual params out of one. PITA.

So, I&#039;m going back to PDO. If I don&#039;t go back to Perl first.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a good reason to like PDO and hate the MYSQLi.</p>
<p>Let&#8217;s say that you&#8217;re making a mapper class. And in the mapper class, you&#8217;re trying to create an &#8220;insert($objects)&#8221; method that can go get the relevant fields from the object, and insert them.</p>
<p>The way I tried to do it was to count up the fields, use that to make a string of &#8220;?,?,?&#8221; placeholders, and then pass the array of values into execute(). That works in PDO, the way it does in Perl DBI.</p>
<p>But not with mysqli. As far as I can tell, with mysqli, you prepare the statement, and then you have to bind them explicitly like so:</p>
<p>  $stmt-&gt;bind_params(&#8220;sss&#8221;, $foo, $bar, $baz);</p>
<p>Whatever, seems like BS to me. But more importantly, if I&#8217;m passing in an array with an arbitrary number of insert values:</p>
<p>1. now I have to do some kind of meta-info about each object attribute? so i can create that string? Bullocks.<br />
2. as far as i know, correct me if I&#8217;m wrong, I can&#8217;t just do $stmt-&gt;bind_params(&#8220;sss&#8221;, @attrs), they have to be broken out into individual variables. Again, bad bad bad. If this was Perl, it wouldn&#8217;t care if I passed in a list of vars or an array. But in PHP, it&#8217;s much easier to put things into an param array than to bust individual params out of one. PITA.</p>
<p>So, I&#8217;m going back to PDO. If I don&#8217;t go back to Perl first.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-4132</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Mon, 02 Apr 2007 20:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-4132</guid>
		<description>PDO is not bad.
The situation may dictate if you use mysqli or PDO.

mysqli works only on MySQL.
PDO can work with many databases.

So, if work with a large project, PDO could be the winner.
I have been using PDO, and i&#039;m very happy. Zend Framework has implemented it.</description>
		<content:encoded><![CDATA[<p>PDO is not bad.<br />
The situation may dictate if you use mysqli or PDO.</p>
<p>mysqli works only on MySQL.<br />
PDO can work with many databases.</p>
<p>So, if work with a large project, PDO could be the winner.<br />
I have been using PDO, and i&#8217;m very happy. Zend Framework has implemented it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ramblings of a web guy &#187; Blog Archive &#187; MySQLi vs. PDO (my version)</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-51</link>
		<dc:creator>Ramblings of a web guy &#187; Blog Archive &#187; MySQLi vs. PDO (my version)</dc:creator>
		<pubDate>Mon, 07 Aug 2006 23:15:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-51</guid>
		<description>[...] The recent post by SantosJ reminded me of a write up I did for the dealnews developer page. His post dealt with the good and bad of coding with PDO. For me, it was about speed, not ease of use. I will write any freaky code to save a cycle or two. In my tests (code is on the linked page), I found that PDO was slower than mysqli in every test except prepared inserts. Since the bulk of our application (and I suspect, most web apps) is read bound, that is not a big win for me. I was happy to see however that mysqli was in no way slower than the trusty old mysql extension. Good job to whomever did that extension.     Posted by doughboy Filed in Programming, PHP [...]</description>
		<content:encoded><![CDATA[<p>[...] The recent post by SantosJ reminded me of a write up I did for the dealnews developer page. His post dealt with the good and bad of coding with PDO. For me, it was about speed, not ease of use. I will write any freaky code to save a cycle or two. In my tests (code is on the linked page), I found that PDO was slower than mysqli in every test except prepared inserts. Since the bulk of our application (and I suspect, most web apps) is read bound, that is not a big win for me. I was happy to see however that mysqli was in no way slower than the trusty old mysql extension. Good job to whomever did that extension.     Posted by doughboy Filed in Programming, PHP [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wez Furlong</title>
		<link>http://jacobsantos.com/2006/general/mysqli-vs-pdo/comment-page-1/#comment-49</link>
		<dc:creator>Wez Furlong</dc:creator>
		<pubDate>Mon, 07 Aug 2006 00:44:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.santosj.name/?p=264#comment-49</guid>
		<description>I think you&#039;re hating it because you&#039;re writing too much code.

KISS:
&lt;code&gt;
try {
    $statement = $mysql-&gt;prepare(&quot;SELECT COUNT(*) FROM gh_users
            WHERE username=:username AND pass=PASSWORD(:password)&quot;);

    $statement-&gt;execute(array(
         &#039;username&#039; =&gt; $_POST[&#039;username&#039;],
         &#039;password&#039; =&gt; $_POST[&#039;password&#039;]
    ));

    $row = $statement-&gt;fetch(PDO::FETCH_NUM);

    if ($row[0]) {
        $_SESSION[&#039;username&#039;] = $_POST[&#039;username&#039;];
        $_SESSION[&#039;password&#039;] = $_POST[&#039;password&#039;];

    }
} catch(PDOException $e) {
   var_dump($e);
}
&lt;/code&gt;

A common newbie mistake with PDO is wondering why it doesn&#039;t report errors.  You need to tell PDO that you want either warnings or exceptions, otherwise it will assume that you&#039;re being a good coder and checking return values and calling errorCode() and errorInfo() in the right places.</description>
		<content:encoded><![CDATA[<p>I think you&#8217;re hating it because you&#8217;re writing too much code.</p>
<p>KISS:<br />
<code><br />
try {<br />
    $statement = $mysql-&gt;prepare("SELECT COUNT(*) FROM gh_users<br />
            WHERE username=:username AND pass=PASSWORD(:password)");</p>
<p>    $statement-&gt;execute(array(<br />
         'username' =&gt; $_POST['username'],<br />
         'password' =&gt; $_POST['password']<br />
    ));</p>
<p>    $row = $statement-&gt;fetch(PDO::FETCH_NUM);</p>
<p>    if ($row[0]) {<br />
        $_SESSION['username'] = $_POST['username'];<br />
        $_SESSION['password'] = $_POST['password'];</p>
<p>    }<br />
} catch(PDOException $e) {<br />
   var_dump($e);<br />
}<br />
</code></p>
<p>A common newbie mistake with PDO is wondering why it doesn&#8217;t report errors.  You need to tell PDO that you want either warnings or exceptions, otherwise it will assume that you&#8217;re being a good coder and checking return values and calling errorCode() and errorInfo() in the right places.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
