Php-pdo MySQL parameter bindings

Source: Internet
Author: User
Tags dsn

<?PHP/*PDO Learning*/    $dsn= ' MYSQL:HOST=LOCALHOST;DBNAME=CSWL ';//Build a Connection DSN    $db=NewPdo$dsn, ' root ', ');//instantiate PDO "the second parameter is the user name, the third is the password"    #. Query    $obj=$db->prepare ("select * from level_class where id =?")); $id= 28; $obj->bindparam (1,$idPdo::param_int); $obj-execute (); $result=$obj->fetchall (PDO::FETCH_ASSOC); Var_dump($result);?>

PDO supports two types of parameter binding schemes:

1. What if the SQL ' statement is used? Number as a placeholder, in the Bindparam parameter, the first parameter is filled in the order of placeholders, such as 1 for the first one? The value of the number

2. If the SQL statement uses ": Variable name" as a placeholder, then the first parameter in the Bingparam parameter is ": Variable name"

Ps:bindparam function: par1, placeholder identifier, PAR2: value (must be represented as variable, otherwise reported: cannot pass parameter 2), PAR3: Value mode

With PDO::P aram_int,pdo::P aram_str,....

Related Article

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.