views:

2144

answers:

4

Duplicate: mysqli or PDO - what are the pros and cons?

I'm looking to move a website from mysql to either mysqli or pdo as primarily a learning tool, but also for performance increases if possible.

I have read through http://php.net/manual/en/mysqli.overview.php and it seems like both would suit my needs, but it doesn't lean strongly either way.

The site currently uses primarily non object orientated code, but I do have experience with OO in other languages. A huge majority of the queries are simple complex select statements with very little update/inserts. What do you suggest as being the most useful both from my own education and for this specific site?

If you need any additional information please let me know.

Thanks.

+6  A: 

PDO Pro's:

  • Native to PHP as of 5.x
  • Supports named parameters as opposed to numerically indexed ?'s
  • Same abstraction library supports multiple different RDBM's

Mysqli Con's:

  • Has issues with properly storing and retrieving large objects in the database.
  • No support for named parameters.

Otherwise, both libraries are basically different flavors of the same thing. They both have functions to quote parameters and both support parameterized queries.

If none of the above arguments sway you, then go with whichever library you prefer based on its syntax, style, etc.

Noah Goodrich
+2  A: 

PDO offer great security than other without much hassle, but for transition i would suggest you to move to mysqli since it faster, easier than PDO, and most api/syntax are quite same with the old mysql extension

See here (scroll below) for quick comparisson:
PHP & MySQLi

Edit: Looks like it same link as you've read before, sorry

Dels
+1  A: 

I don't believe PDO would give you any performance increase, but it gives you these two very attractive long-term benefits:

  • you can scale your app to use other databases with just a few code changes
  • the PDO library has much of the security built in

If you don't understand the benefits to #1 and #2, then just stick with the tried-and-true mysql library (*you are at least using mysql_real_escape_string though, right*)?

If I were learning a new PHP database library, I believe PDO is the way to go, especially if you are creating a web app that may be used on a variety of systems other than your own server.

OneNerd
A: 

When building my ORM and abstraction library I used MySQLi and PDO to see which one performs better. MySQLi was faster - but not enough to make the choice based on that alone.

One thing that MySQLi/MySQL/SQLite or any of the other independent libraries have over PDO is that they return the number of rows found in the result which often helps to test for any results at all. Meanwhile, in PDO you either fetchAll() results and count() them - or run a count query before to see the number of results. So you have to adapt to handle this problem in different ways.

Oh, and I choose PDO over MySQLi in the end.

Xeoncross