Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which one is faster and lighter - mysqli & PDO

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.

like image 397
Alfred Avatar asked May 22 '12 06:05

Alfred


People also ask

Is MySQLi faster than MySQL?

The MySQL extension is very slightly faster than MySQLi in most benchmarks I've seen reported. The difference is so slight, however, that this should probably not be your criterion for deciding between the two. Other factors dwarf the difference in performance between mysql and mysqli.

What is advantage of PDO or MySQLi?

Both MySQLi and PDO have their advantages: PDO will work on 12 different database systems, whereas MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries.

Should I use MySQLi or MySQL?

What is the difference between mysql and mysqli? Basically, MySQL is the old database driver, and MySQLi is the Improved driver. The "i" stands for "improved" so it is MySQL improved. MySQLi can be done procedural and object-oriented whereas MySQL can only be used procedurally.

Is PDO safer than MySQLi?

There is no difference in security. The main difference between PDO and Mysqli is that PDO supports various databases and mysqli supports only MySQL. MySQLi is also a bit faster. PDO supports 12 different drivers, opposed to MySQLi, which supports MySQL only.


1 Answers

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 .

like image 111
AlphaMale Avatar answered Oct 12 '22 02:10

AlphaMale