PDO Functions Library in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:38:13
Original
838 people have browsed it

PDO is a "database access abstraction layer" that unifies the access interfaces of various databases. Compared with the function libraries of mysql and mysqli, PDO makes cross-database use more friendly; compared with ADODB and MDB2, PDO is more efficient. 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() — marks the starting point of rollback
PDO->commit() — Mark the rollback end point and execute SQL
PDO->__construct() — Create an instance of PDO linked database
PDO->errorCode() — Get error code
PDO->errorInfo() — Get error information
PDO->exec() — Process a SQL statement and return the number of entries affected
PDO->getAttribute() — Get the attributes of a "database connection object"
PDO->getAvailableDrivers() — Get valid PDO driver names
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 quotes to a string in SQL
PDO->rollBack() — Perform a 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 (produced by new PDO), and "PDOStatement" represents a query object (produced by PDO->query() ) or a result set object (produced by PDO->prepare()).
An example of a "Database Connection Object", returning "PDO":
$dbh = new PDO(mysql:host=localhost;dbname=test, root, );
?>

An example of "query object", returning "PDOStatement":
$sql = "INSERT INTO `test`.`table` (`name` ,`age`)VALUES (?, ?);";
$stmt = $dbh->prepare($sql);
?>

An example of a "result set object", returning "PDOStatement":
$sql = "SELECT * FROM `table` WHERE `name` = samon";
$stmt = $dbh->query($sql);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486505.htmlTechArticlePDO is a database access abstraction layer that unifies the access interfaces of various databases and functions with mysql and mysqli Compared with libraries, PDO makes cross-database use more friendly; compared with ADOD...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template