12

I am using MySQL with PHP5. I got to know that ancient mysql_* functions are no longer maintained and community has begun the deprecation process. So I decided to move away from mysql_*. The question is where to? I am looking for lighter, simpler and faster way. Somebody tell me which among these (mysqli and PDO) is;

  1. faster
  2. easy to learn and code
  3. consumes less space and memory

Note: Tutorial links in beginner level for these two will be helpful.

Alfred
  • 21,058
  • 61
  • 167
  • 249

3 Answers3

35

PDO vs. MySQLi: Which Should You Use?

Both PDO and MySQLi offer an object-oriented API, but MySQLi also offers a procedural API – which makes it easier for newcomers to understand. If you are familiar with the native PHP MySQL driver, you will find migration to the procedural MySQLi interface much easier. On the other hand, once you master PDO, you can use it with any database you desire!

Summary

DataBase Support

Ultimately, PDO wins this battle with ease. With support for twelve different database drivers (eighteen different databases!) and named parameters, we can ignore the small performance loss, and get used to its API. From a security standpoint, both of them are safe as long as the developer uses them the way they are supposed to be used.

So if you’re still working with MySQLi, maybe it’s time for a change!

PDO vs. MySQLi: Which Should You Use? - By Dejan Marjanovic

Hope this helps .

talha2k
  • 24,937
  • 4
  • 62
  • 81
  • Both extensions support the [MySQL Native Driver](http://dev.mysql.com/doc/refman/5.5/en/apis-php-mysqlinfo.library.choosing.html) which is a hell of a beast and if you're using Mysql + PHP you need to understand that this is a luxury position in web-development. – hakre Jun 03 '12 at 21:01
  • 1
    So you copied over large parts of an article written by someone else and gave that as "your" answer? You should praise the guy who has wrote that piece I suggest before doing so. – hakre Jun 03 '12 at 21:34
  • 1
    @hakre I've mentioned him dude. and if some one have written it in a better way then why need to write a whole new answer. Got my point?! – talha2k Jun 04 '12 at 04:55
  • @AlphaMale: I don't see Webarto's name here. Learn how to properly quote and how to give credit. – hakre Jun 04 '12 at 08:14
  • What do you mean mysqli doesn't support prepared statements? The documentation says otherwise: http://php.net/manual/en/mysqli.prepare.php – ashgromnies Jul 20 '12 at 14:20
  • @ashgromnies It says clearly "CLIENT-SIDE PREPARED STATEMENTS", MYSQLi extension does not supports clientside prepared statements but using Using PDO MySQL Driver and MySQL Native Driver you can d that easily. The Same Documentation says this too: http://php.net/manual/en/mysqli.overview.php#usernotes – talha2k Jul 20 '12 at 15:48
  • @ashgromnies and here it is also mentioned clearly "The API does not include emulation for client-side prepared statement emulation." have a look: http://php.net/manual/en/mysqli.quickstart.prepared-statements.php For further clearance on what client-side statements are Please visit http://stackoverflow.com/questions/10146733/what-are-client-side-prepared-statements – talha2k Jul 20 '12 at 15:54
0

Along with the above question, here is a comparison chart;

enter image description here

And the information at Why you Should be using PHP’s PDO for Database Access is really helpful.

Alfred
  • 21,058
  • 61
  • 167
  • 249
0

About Performance

While both PDO and MySQLi are quite fast, MySQLi performs insignificantly faster in benchmarks - ~2.5% for non-prepared statements, and ~6.5% for prepared ones. The MySQL extension was even faster.

Chirag Shah
  • 1,463
  • 2
  • 18
  • 40