PHP,PDO Pre-compilation technology

Source: Internet
Author: User

(1)

      

For example, the following statement:

1INSERT into BIAO1 values (' Li Ning ', ' -');2INSERT into BIAO1 values (' Anta ', ' -');3INSERT into BIAO1 values (' Pico ', ' -');4INSERT into BIAO1 values (' Jordan ', ' -');5INSERT into BIAO1 values (' Nike ', ' -');6INSERT into BIAO1 values (' Artie ', ' -');7INSERT into BIAO1 values ('361’,‘ -’);

Then, this PDO can just compile the same place for these statements once, and then execute the different statements according to the difference.

1 or, for example , 2 INSERT INTO team values (NULL, ' Guoan '); 3 INSERT INTO team values (NULL, ' Evergrande '); 4 INSERT INTO team values (NULL, ' Jianguo '); 5 INSERT INTO team values (NULL, ' green space ');

The implementation of the syntax:

    

1 (1) Compile the unified structure,2 (2) bind the data to the intermediate compilation result,3 ( 3) Execute the statement that binds the data
1 (1) Compile a unified structure,2             $PDOStatement = $pdo-Prepare (SQL structure); 3             In the data section of the SQL structure, you can use Hello or the syntax of the colon tag to occupy:

1 (2) bind data to intermediate compilation results,2              $PDOStatement->bindvalue ()

1 (3) executes the data-bound statement     2               $PDOStatement->execute ();

Pre-compilation Benefits:

Better to prevent SQL injection because the user's data does not need to be involved when precompiling. At compile time, the structure is fixed, resulting in user data not affecting the structure of SQL

Common methods of execution:

$pdo->query ();

$pdo->exec ()

If you need to prevent SQL injection , you need to manually escape user data by using the $pdo->quote () method. Escape and enclose with quotation marks.

    

PHP,PDO Pre-compilation technology

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.