beginTransaction() — Indicates the starting point of rollback PDO->commit() — Indicates the end point of rollback and executes SQL PDO->__construct() — Creates an instance of PDO linked to the database PDO->er"/> beginTransaction() — Indicates the starting point of rollback PDO->commit() — Indicates the end point of rollback and executes SQL PDO->__construct() — Creates an instance of PDO linked to the database PDO->er">
Home >Backend Development >PHP Tutorial >blendfunction PHP PDO function library (PDO Functions) page 1/2
PDO is more efficient compared to ADODB and MDB2. At present, there is a long way to go to implement the "database abstraction layer". Using a "database access abstraction layer" such as PDO is a good choice.
PDO->beginTransaction() — Mark the starting point of rollback
PDO->commit() — Mark the end point of rollback and execute SQL
PDO->__construct() — Create an instance of PDO link database
PDO ->errorCode() — Get the error code
PDO->errorInfo() — Get the error information
PDO->exec() — Process an SQL statement and return the number of entries affected
PDO->getAttribute () — Get the properties of a "database connection object"
PDO->getAvailableDrivers() — Get the valid PDO driver name
PDO->lastInsertId() — Get the primary key value of the last piece of data written
PDO- >prepare() — Generate a "query object"
PDO->query() — Process a SQL statement and return a "PDOStatement"
PDO->quote() — Add to a string in a SQL Quotes
PDO->rollBack() — Perform rollback
PDO->setAttribute() — Set attributes for a "database connection object"
PDOStatement->bindColumn() — Bind a column to a PHP variable
PDOStatement ->bindParam() — Binds a parameter to the specified variable name
PDOStatement->bindValue() — Binds a value to a parameter
PDOStatement->closeCursor() — Closes the cursor, enabling the statement to be executed again .
PDOStatement->columnCount() — Returns the number of columns in the result set
PDOStatement->errorCode() — Fetch the SQLSTATE associated with the last operation on the statement handle
PDOStatement->errorInfo() — Fetch extended error information associated with the last operation on the statement handle
PDOStatement->execute() — Executes a prepared statement
PDOStatement->fetch() — Fetches the next row from a result set
PDOStatement->fetchAll() — Returns an array containing all of the result set rows
PDOStatement->fetchColumn() — Returns a single column from the next row of a result set
PDOStatement->fetchObject() — Fetches the next row and returns it as an object.
PDOStatement->getAttribute() — Retrieve a statement attribute
PDOStatement->getColumnMeta() — Returns metadata for a column in a result set
PDOStatement->nextRowset() — Advances to the next rowset in a multi -rowset statement handle
PDOStatement->rowCount() — Returns the number of rows affected by the last SQL statement
PDOStatement->setAttribute() — Set a statement attribute
PDOStatement->setFetchMode() — Set the default fetch mode for this statement
As can be seen from the function list, operations are based on different objects. "PDO" represents a database connection object (generated by new PDO), and "PDOStatement" represents a query object (PDO->query( ) or a result set object (produced by PDO->prepare()).
An example of "Database Connection Object", returning "PDO":
Copy code The code is as follows:
$dbh = new PDO('mysql:host=localhost;dbname=test ', 'root', '');
?> sql = "INSERT INTO `test`.`table` (`name` ,`age`)VALUES (?, ?);";
$stmt = $dbh->prepare($sql);
An example of a "result set object", returning "PDOStatement": Copy code
The code is as follows:
$sql = "SELECT * FROM `table` WHERE `name` = 'samon'";
$stmt = $dbh->query($sql);
Current 1/2 page 12Next page The above introduces the blendfunction PHP PDO function library (PDO Functions) page 1/2, including the blendfunction content. I hope it will be helpful to friends who are interested in PHP tutorials.