PDO function library (PDOFunctions) in PHP)

Source: Internet
Author: User
PDO is a database access abstraction layer used to unify access interfaces of various databases. compared with mysql and mysqli function libraries, PDO makes cross-database use more friendly; compared with ADODB and MDB2, PDO is more efficient. At present, there is a long way to implement the database abstraction layer. Using a database such as PDO to access the abstraction layer is a good choice. PD "> <LINKhref =" http: // w

PDO is a "database access abstraction layer" that unifies Access interfaces of various databases. compared with mysql and mysqli function libraries, PDO makes cross-database use more friendly; 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 ":
$ Dbh = new PDO ('MySQL: host = localhost; dbname = test', 'root ','');
?>

In an example of "query object", "PDOStatement" is returned ":
$ SQL = "INSERT INTO 'test'. 'Table' ('name', 'age') VALUES (?, ?); ";
$ Stmt = $ dbh-> prepare ($ SQL );
?>

In an example of "result set object", "PDOStatement" is returned ":
$ SQL = "SELECT * FROM 'table' WHERE 'name' = 'samon '";
$ Stmt = $ dbh-> query ($ SQL );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.