Home > Article > Backend Development > How to operate mysql, mysqli, PDO with PHP
This article mainly shares with you how to operate mysql, mysqli, and PDO with PHP. We will first briefly introduce mysql, mysqli, and PDO to you, hoping to help you.
1. Ordinary PHP operation of the mysql database is to operate the contents of the database through some of the functions and methods that come with PHP.
Moreover, mysql does not continuously connect to the database and will be opened every time. A connection process adds access pressure to the server.
2.mysqli extension library operates the database
mysqli is a permanent connection process. No matter how many times you connect to the database, it is the same connection process
Reduces server overhead, and mysqli is an object-oriented development
Operate the database through the operation of objects
Use some methods in the object to operate the database
And mysqli adds preprocessing and transaction processing, which increases the security and
completeness of the database.
Preprocessing can write a statement and put it there to occupy the position, waiting for the customer to perform operations, and
Every time the customer submits information, the program will only view it as a whole part, thereby improving
The security of the database prevents some technical people from destroying the database through value-passing splicing (sql injection)
Only InnoDB and BDB engines support transactions, and transaction processing can make the program more complete
For example: in the transfer system, only when the money amounts of the transferor and the payee are updated, will the transferor and the payee be allowed to submit
Otherwise, it will be rolled back and will not be allowed to submit
3. PDO extension library operation database
Provided by PDO A database access abstraction layer is created. We operate the database by operating PDO. There is no need to judge what kind of database to use.
It can be executed through consistent function methods.
PDO facilitates cross-database development
and PDO operations The database is also object-oriented development
and PDO also has pre-processing and transaction processing, so the security of PDO is also very high
PDO operation database:
Use the exec() method to perform additions, deletions and changes
Perform query operations Use the query() method.
Related recommendations:
A brief analysis of mysql, mysqli, PDO_MySQL
The above is the detailed content of How to operate mysql, mysqli, PDO with PHP. For more information, please follow other related articles on the PHP Chinese website!