Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving from mysql to mysqli or pdo? [closed]

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.

like image 668
Rob Avatar asked Apr 21 '09 02:04

Rob


3 Answers

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.

like image 181
Noah Goodrich Avatar answered Oct 17 '22 16:10

Noah Goodrich


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.

like image 29
OneNerd Avatar answered Oct 17 '22 16:10

OneNerd


From http://www.php.net/manual/en/mysqli.overview.php :

While PDO has its advantages, such as a clean, simple, portable API, its main disadvantage is that it doesn't allow you to use all of the advanced features that are available in the latest versions of MySQL server. For example, PDO does not allow you to use MySQL's support for Multiple Statements.

like image 8
Anas Avatar answered Oct 17 '22 16:10

Anas