What is the difference between MySQLi and PDO?
I recently started learning PHP. I found out there were many changes and now SQL is being avoided and replaced with MySQLi , but then I found out about PDO. I have read many posts about these two topics, but each has their own opinion and I am confused. Many posts have stated that MySQLi supports procedural and object oriented method, whereas PDO only supports object oriented method.
I want to know that:
-
Are these two (PDO and MySQLi) two different ways of doing the same thing or are they different from each other?
-
If they are just two different ways of doing the same thing, then what is the difference between them and what is the best way to accomplish the task?
-
If you're learning MySQLi, what's the best method between object-oriented and procedural?
This may seem like a broad question to some, but I would really appreciate it if anyone can provide a specific answer to these three questions.
source to share
PDO is an interface for accessing databases:
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing PHP databases. Each database driver that implements the PDO interface can expose database-specific functions as regular extension functions. Note that you cannot perform any database functionality using the PDO extension itself; you must use the database specific PDO driver to access the database server. ( source )
MySQLi is an extension for accessing MySQL databases:
The mysqli extension allows you to access the functionality provided by MySQL 4.1 and higher. ( source )
Which one you should use is mostly opinion based and not particularly well suited to the Stack Overflow format.
source to share
When accessing a database in PHP, we have two options: MySQLi and PDO. So, what should you know before choosing one?
- PDO has 12 different drivers, while MYSQLI only has one ie MYSQL.
- PDO uses the OOP API while MySqli uses both OOP and Predic
- PDO named the parameters, but MuSqli doesn't.
- With PDO, you can prepare client-side instructions
source to share