Home > Backend Development > PHP Tutorial > PHP PDO Functions Library (PDO Functions) Page 1/2_PHP Tutorial

PHP PDO Functions Library (PDO Functions) Page 1/2_PHP Tutorial

WBOY
Release: 2016-07-21 15:45:51
Original
764 people have browsed it

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() — Marks the starting point of rollback
PDO->commit() — Marks the end point of rollback and executes SQL
PDO->__construct() — Creates a PDO Instance of linked database
PDO->errorCode() — Get error code
PDO->errorInfo() — Get error information
PDO->exec() — Process a SQL statement and Returns the number of entries affected
PDO->getAttribute() — Gets the attributes of a "Database Connection Object"
PDO->getAvailableDrivers() — Gets 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 quotes to a string in a SQL
PDO->rollBack() — Perform rollback
PDO->setAttribute() — Set properties 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
PDOStatement->getAttribute() — Retrieve a statement attribute
PDOStatement->getColumnMeta() — Returns metadata for a column in a result set 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, the operation is based on different objects. "PDO" represents a database connection object (generated by new PDO). "PDOStatement" represents a query object (produced by 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:
< ;?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', '');
?>

A "query Object" example, returns "PDOStatement":

Copy code The code is as follows:
$ 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 );
?>


http://www.bkjia.com/PHPjc/320272.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320272.htmlTechArticleCompared 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...
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