Should I have to upgrade my website to PHP MySQLi or PDO?

后端 未结 3 804
天命终不由人
天命终不由人 2021-01-19 00:14

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 a

相关标签:
3条回答
  • 2021-01-19 00:39

    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.

    0 讨论(0)
  • 2021-01-19 00:55

    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.

    0 讨论(0)
  • 2021-01-19 00:56

    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

    0 讨论(0)
提交回复
热议问题