That was great answer, thanks Thomas. As I expected, you can't be wrong using one or another, and using mysqli is not a bad thing (if you are using PHP 5.3+) :)
Regards, Saša Stamenković On Wed, May 26, 2010 at 1:11 PM, Thomas D. <[email protected]> wrote: > Hi, > > Саша Стаменковић wrote: > > Still, I'm not really informed about differences between mysqli > > and pdo. When you work with Zend_Db, you can choose between this > > 2 with just one config param. > > > > I would like to know which one is faster? > > This question will be asked every month ;-) > > You should first understand, what's the difference between these two (well, > there are 3 "adapters", in PHP 5.3 there you can choose between 4 > "adapters") are. To do that, have a look at the native PHP stack, how these > adapters are implemented and what they do. > > PDO for example is just another layer, which should "abstract" the database > access (that's why PDO supports different DBEs and mysql* only MySql ;-)). > > In general: Everything which is abstracting something will be slower than a > native implementation of the same thing, because of the "overhead". But you > should benefit from a great abstraction, so abstraction isn't bad at all ;-) > > So when you are using Zend_Db_*, you are already using some kind of > "abstraction", so you don't really need another abstraction, some PHP > database API is offering to you. > > In theory, PDO should be much slower than ext/mysql or mysqli is. For > example PDO will prepare everything. But the nature of a PHP script is, that > it will die after each request, so a prepared statement can only be used > while the request, which prepared the statement, is active. So preparing a > simple "SELECT * FROM articles WHERE isPublished = 1 ORDER BY date DESC" > doesn't really makes sense, because this query will just be executed once in > the request. > > If you would prepare a select statement and execute it more than once with > different parameters in one request, you would benefit from preparation > (well, only when preparation is done on server-side, client-side prepared > statements are another kind of abstraction and therefore aren't as good as > server-side prepared statements). > > So PDO is bad, isn't it? ;) > > No! If you don't use any kind of abstraction like Zend_Db* is offering to > you, the client-side prepared statements are offering you some kind of > security. Binding parameters to a query makes them secure against known SQL > injections. > At least other DBEs just need to implement the PDO interface to support > PHP. They don't need to re-invent everything. > > Ergo: > When you are using Zend_Db*, I would recommend to use ext/mysql or mysqli, > because it's faster and you are already using a abstracted DBA. > > If you don't use a abstracted DBA, I would recommend to use PDO. > > In a normal application, you shouldn't notice any differences. > > Only on high traffic applications you would notice differences. But in high > traffic applications, you won't use Zend_Db*, because Zend_Db* won't support > the DBE specific (optimized) commands, just "generalized" commands, which > will work across all supported adapters. ;-) > > > P.s.: Ulf Wendel (from MySQL) wrote about that topic some month ago in this > list: < > http://zend-framework-community.634137.n4.nabble.com/PDO-or-Mysqli-td1556941.html > > > > > -- > Regards, > Thomas > > >
