Compared with ADODB and MDB2, PDO is more efficient. At present, there is a long way to implement the "database abstraction layer". Using the "database access abstraction layer" such as PDO is a good choice.
PDO-> beginTransaction ()-indicates the start point of rollback
PDO-> commit ()-indicates the rollback end point and executes the SQL
PDO->__ construct ()-create a PDO-Linked database instance
PDO-> errorCode ()-Get error code
PDO-> errorInfo ()-Get error information
PDO-> exec ()-processes an SQL statement and returns the number of affected items
PDO-> getAttribute ()-Get the attribute of a "database connection object"
PDO-> getAvailableDrivers ()-Get a valid PDO drive name
PDO-> lastInsertId ()-Get the primary key value of the last data entry written
PDO-> prepare ()-generate a "query object"
PDO-> query ()-processes an SQL statement and returns a "PDOStatement"
PDO-> quote ()-add quotation marks for strings in an SQL statement
PDO-> rollBack ()-Execute 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
From the function list, we can see that operations are based on different objects. "PDO" indicates a database connection object (generated by new PDO ), "PDOStatement" indicates a query object (generated by PDO-> query () or a result set object (PDO-> prepare ).
In an example of "database connection object", "PDO" is returned ":
Copy codeThe Code is as follows: <? Php
$ Dbh = new PDO ('mysql: host = localhost; dbname = test', 'root ','');
?>
In an example of "query object", "PDOStatement" is returned ":Copy codeThe Code is as follows: <? Php
$ SQL = "INSERT INTO 'test'. 'table' ('name', 'age') VALUES (?, ?); ";
$ Stmt = $ dbh-> prepare ($ SQL );
?>
In an example of "result set object", "PDOStatement" is returned ":Copy codeThe Code is as follows: <? Php
$ SQL = "SELECT * FROM 'table' WHERE 'name' = 'samon '";
$ Stmt = $ dbh-> query ($ SQL );
?>