5

I have designed a website before 5 years using PHP MySQL and still works fine without any issues. I heard MySQL is officially deprecated as of PHP 5.5 and has been removed as of PHP 7. Also, PHP offers three different APIs to connect to MySQL (like MySQL, MySQLi, and PDO). My web server is updated frequently.

I understood, I have to move to newer API like MySQLi or PDO for safety. Now I am confused whether to choose MySQLi or PDO. Also, Is there any compatibility/migrating options available for such case?

ak-SE
  • 980
  • 1
  • 7
  • 27
  • Regarding whether to chose MySQLi or PDO is primarily opinion-based, with that said, I believe some would say PDO is the safest of the two, but I don't know whether that's accurate or not. If you're coming from mysql I believe MySQLi will be easier to get a grasp of. – Epodax Feb 25 '16 at 08:04
  • I recommend you not to upgrade the PHP version nor the MySQL version. If the website is working then let it work. version upgrade should be manually and not automatically – zion ben yacov Feb 25 '16 at 08:05
  • 1
    A guide about PDO, which I would say is the obvious choice - https://phpdelusions.net/pdo – DTH Feb 25 '16 at 08:23
  • Possible duplicate of [mysqli or PDO - what are the pros and cons?](http://stackoverflow.com/questions/13569/mysqli-or-pdo-what-are-the-pros-and-cons) – Cees Timmerman Apr 20 '17 at 14:17

3 Answers3

4

Lets take a look at both of these extensions.

PDO

PDO is database neutral - You only need to learn one API to work with dozens of databases

So if you decide to move to another database, the only thing you would be changing is the DSN(data source name).

Support of both name and '?' placeholders for prepared statements.

Drupal uses PDO.

Mysqli

On the other hand Mysqli is designed specifically for Mysql databases and is recommended by Mysql. Mysqli works with Mysql and MariaDB databases.

Support of only '?' placeholders for prepared statements.

Joomla uses Mysqli

Conclusion

There are many conflicting arguments weather Mysqli or PDO runs faster. Both Mysqli and PDO use the same underlying drivers to access the database making the performance not worth comparing.

So there is no clear winner when working with Mysqli or PDO. But let's say you use Mysqli and then later you want to use another database, it would be a difficult transition.

The main strength of PDO over Mysqli is name placeholders for prepared statements and which is why I chose PDO over Mysqli.

Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
2

The answer is fairly simple.

If, like majority of PHP users, you are going to use database API functions right in the application code, without any intermediate wrapper, then PDO is your only choice, as it's a sort of wrapper already, automating many operations that with mysqli have to be done manually.

No, there are no migration options, because the very approach is changed dramatically: instead of placing variables right in the query, they have to be substituted in the query with special marks. There is no way to automate this process.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • PDO is not your only choice. mysqli_ is also a choice. And in some ways a better choice as it is more comparable to mysql_. Depending on how much rewrite is desired, or even allowed, PDO might not even be a feasible choice. – jmarkmurphy Aug 03 '17 at 20:06
  • @jmarkmurphy your comment is factually incorrect. You can't claim `mysqli` is better than `PDO` if: 1) `mysqli` works only with MySQL 2) `mysqli` has a more complex interface 3) Being comparable to `mysql_` is a step backwards, not forward - hence, no it is not better. Stating that `PDO` might not even be a feasible choice makes no sense, isn't backed with a single provable evidence and is only your *opinion*. And you know what they say about opinion in an area that relies on mathematics and logic? – N.B. Aug 04 '17 at 19:58
-2

PDO and MySQli both are used for database connection and both have their own advantage. In closer look PDO wins the battle but if you really stick with only one database provider then my personal best choice is use MySQLi.

You will also extract some good points from: http://code.tutsplus.com/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059