In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what is PHP PDO". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. The PDO (PHP Data Object) extension defines a lightweight, persistent interface for PHP to access the database. Each database driver that implements the PDO interface can show its own characteristics in the form of regular extension.
Main: PDO extension is only an abstract interface layer. Using PDO extension itself can not realize any database operation. You must use a specific database PDO driver to access the database.
2. Start the PDO method: find the php.ini file and
The copy code is as follows:
; extension=php_pdo.dll
Just remove the front semicolon (similar in linux environment)
3. PDO predefined classes:
PDO contains three predefined classes: PDO, PDOStatement, and PDOException
(1) PDO class: represents a connection between a PHP and a database
PDO: constructor to create a new PDO object
BeginTransaction: start a transaction
Commit: commit transaction
ErrorCode: returns an error code from the database, if any
ErrorInfo: returns an array of error messages from the database, if any
Exec: executes a SQL statement and returns the number of rows affected
GetAttribute: returns the connection properties of a database
LastInsertId: returns the latest row inserted into the database (ID)
Prepare: prepares a SQL statement for execution and returns the federated result set after the statement is executed
Query: executes a SQL statement and returns the result set
RollBack: rolls back a transaction
SetAttribute: set a database connection property
(2) PDOStatement class: represents a preprocessing statement and the federated result set after the statement is executed
BindColomn: bind a PHP variable to the output column of the result set
BindParam: bind a variable to a parameter in a PHP preprocessing statement
BindValue: bind a value to a parameter in a processing statement
CloseCursor: close the cursor so that the statement can be executed again
CloumnCount: returns the number of columns in the result set
ErrorCode: returns an error code from the statement, if any
ErrorInfo: returns an array containing error messages from a statement
Execute: execute a preprocessing statement
Fetch: fetches a row from the result set
FetchAll: fetches an array containing all rows from the result set
FetchColomn: returns the data of a column in the result set
GetAttribute: returns a PDOStatement property
GetColomnMeta: returns the structure of a column in the result set
NextRowset: returns the next result set
RowCount: returns the number of rows affected after the execution of the SQL statement
SetAttribute: set a PDOStatement property
SetFetchMode: setting for PDOStatement to get data
Give a simple example of transaction processing:
The copy code is as follows:
(main features of transactions: atomicity, consistency, independence, and persistence)
4. The most important feature of PDO is the introduction of parameter binding and precompilation.
Precompilation is responsible for two things, transfer and soft parsing speed up. To support precompilation, driver support (PDO and NySQLi support) is required in addition to database support.
5. The efficiency of PDO
(1) when tested in a large table and a large amount of data, the CRUD efficiency of PDO is 5% and 15% lower than that of MySql direct connection, and the variance is greater than that of MySQL direct connection.
(2) as for the load, the load of PDO is higher than that of MySQL and is relatively stable after opening the persistent connection.
This is the end of "what is PHP PDO". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.