PHP's Pdo-prepare

Source: Internet
Author: User

When the same SQL multiple query (execution), only each time the query condition (data) is not the same, then the use of prepare is right.

It can significantly reduce query (execution) time and server resource consumption.


Prototype:

Pdostatement PDO::p repare (string query [, array driver_options])


PLACEHOLDER:

1, well-known placeholder (: named parameters)

2, question mark placeholder (?)

Such as:

INSERT into Products Set sku =: SKU, NAME =: Name;insert to products set sku =?, name =?;


Binds a parameter to the specified variable name:

BOOL Pdostatement::bindparam (mixed $parameter, mixed & $variable [, int $data _type = PDO::P aram_str [, int $length [ , mixed $driver _options]])//Name Placeholder $stmt->bindparam (': SKU ', $sku); $stmt->bindparam (': Title ', $title);//question mark placeholder $ Stmt->bindparam (1, $sku); $stmt->bindparam (2, $title);


To perform the steps:

$DBH->prepare (); Prepare $dbh->bindparam (); Binding parameter $dbh->execute (); Perform


Query returns the number of fields:

Integer Pdostatement::columncount ()

Returns the next row of data from the result set:

Mixed Pdostatement::fetch ([int fetch_style [, int cursor_orientation [, int cursor_offset]])

Common Fetch_style:

pdo::fetch_assoc: Returnsan array that is indexed as a result set column name

Pdo::fetch_both(default): Returns an array that is indexed as a result set column name and a column number starting with 0

Pdo::fetch_num: Returns an array whose index is a 0-based result set column number

Pdo::fetch_obj: Returns an anonymous object with a property name corresponding to the result set column name

Pdo::fetch_bound: Returns TRUE and assigns the column values in the result set to the Pdostatement::bindcolumn () method to bind the PHP variable.


Returns an array containing all the rows in the result set

Array Pdostatement::fetchall ([int fetch_style])


Returns a separate column from the next row in the result set

String Pdostatement::fetchcolumn ([int column_number])

Bind column Name:

Boolean pdostatement::bindcolumn (mixed column, mixed &param [, int type [, int maxlen [, mixed driver_options]])


Operational transactions:

Begin:

Boolean pdo::begintransaction ();

Submit:

Boolean pdo::commit ();

Rollback:

Boolean Pdo::commit ()



This article is from the "Web Road" blog, make sure to keep this source http://liuzhongcool.blog.51cto.com/10509488/1674827

PHP's Pdo-prepare

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.