+ 2
CRUD - msqli or PDO?
Considering a MySQL Database, which of those options do you preffer? And why?
1 Odpowiedź
+ 3
Of those alternatives, I would go with PDO.
If you use a PHP framework like Laravel or CodeIgniter, you should use its ORM to connect with the database. The main reason is to keep your code base consistent with the framework's tutorials and documentation. It will also help your database accesses more cohesively connected with models that you've implemented.
mysql functions are not supported in PHP 7 or later. They were deprecated for several years. mysql_* functions would be completely out of question for those reasons.
mysqli is a very reasonable alternative. mysqli could be suitable if you're sure you want to stick with MySQL and want to use more MySQL-specific features. mysqli will be good if you want to optimize your code with asynchronous queries, concurrent queries, use of MySQL triggers, stored procedures... and you're confident your project will never switch to Microsoft SQL Server, Postgres or any other SQL vendor.
If this is a pretty average project that uses fairly standard SQL, PDO will be better since PDO will keep your code more vendor-agnostic. The average web project I worked on needed fairly standard SQL and maintainability was more important than performance so PDO was generally best.
The following article gives a more detailed breakdown of pros and cons with each alternative:
https://websitebeaver.com/php-pdo-vs-mysqli
Some additional pros and cons are listed here:
https://www.phpclasses.org/blog/post/521-mysqli-vs-pdo-vs-mysql.html