Should I upgrade my site to PHP MySQLi or PDO?

I have developed a website up to 5 years old using PHP MySQL and it still works great without any problems. I heard that MySQL is officially deprecated since PHP 5.5 and was removed from PHP 7. In addition, PHP offers three different APIs for connecting to MySQL (for example, MySQL, MySQLi, and PDO). My web server is updated frequently.

I realized I need to upgrade to a new API such as MySQLi or PDO for security. Now I'm confused whether to choose MySQLi or PDO. Also, are there any compatibility / migration options for this case?

+5
source share
3 answers

The answer is pretty simple.

If, like most PHP users, you use the database API functions directly in the application code, without any intermediate shell, then PDO is your only choice , since this is a kind of shell already, automate many of the operations that mysqli should run manually.

No, there are no migration parameters, because the approach itself changes a lot: instead of placing variables directly in the request, they should be replaced with special marks in the request. It is not possible to automate this process.

+2
source

Let's look at both of these extensions.

PDO

PDO is a neutral database. You only need to learn one API for working with dozens of databases

So, if you decide to switch to another database, the only thing you would change is a DSN (data source name).

Name and '?' Support placeholders for prepared statements.

Drupal uses PDO.

Mysqli

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

Support only '?' placeholders for prepared statements.

Joomla uses Mysqli

Conclusion

There are many conflicting arguments that the Mysqli or PDO weather is faster. Both Mysqli and PDO use the same basic drivers to access the database, making performance comparisons impossible.

Thus, there is no clear winner when working with Mysqli or PDO. But let me say that you use Mysqli, and then you want to use a different database, this will be a difficult transition.

The main power of PDOs over Mysqli is name placeholders for prepared statements, which is why I chose PDOs over Mysqli.

+4
source

PDO and MySQli are used to connect to the database, and both have their advantages. Upon closer inspection, PDO wins the battle, but if you really adhere to only one database provider, then my personal best bet is to use MySQLi.

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

-2
source

Source: https://habr.com/ru/post/1243819/


All Articles