Mysqli pre-compilation mechanism for batch data processing, mysqli compilation Mechanism

Source: Internet
Author: User

Mysqli pre-compilation mechanism for batch data processing, mysqli compilation Mechanism

The mysqli enhancement also includes the addition of the Transaction Processing Mechanism and pre-compilation mechanism. In fact, both of them are for the sake of security and execution efficiency. Here we will mainly talk about the pre-compilation mechanism of mysqli.

The so-called pre-compilation is not to compile in the php kernel, but to pre-compile in the database management system. Because it is used for batch data, to put it bluntly, a part of the fixed data format is first compiled on mysql. After compilation, It is not re-compiled. What we need to do is, add and send data to the compiled placeholder (that is, the data placeholder), which greatly reduces the number of compilation times and improves the efficiency of batch processing.


The following is a simple sample code:

<? Php $ mysqli = new MySQLi ("localhost", "root", "toor", "test"); $ SQL = "insert into account (id, blance) values (?,?) "; // You can also add multiple greetings, separated by commas (,) $ mysqli_stmt = $ mysqli-> prepare (" $ SQL "); // create a pre-compiled object/** each piece of data is sent independently */$ id = 6; $ blance = 23; $ mysqli_stmt-> bind_param ("id ", $ id, $ blance); // Add $ B = $ mysqli_stmt-> execute (); // send $ id = 7; $ blance = 33; $ mysqli_stmt-> bind_param ("id", $ id, $ blance); $ B = $ mysqli_stmt-> execute (); $ id = 8; $ blance = 99; $ mysqli_stmt-> bind_param ("id", $ id, $ blance); $ B = $ mysqli_stmt-> execute (); if ($ B) {die ("execution successful");} else {die ("execution failed ". $ mysqli_stmt-> Error) ;}$ mysqli-> close () ;?>
The following is the query operation:

<? Php $ mysqli = new MySQLi ("localhost", "root", "toor", "test"); if (mysqli_connect_error () {die (mysqli_connect_error ());} $ SQL = "select id, blance from account where id>? "; $ Mysqli_stmt = $ mysqli-> prepare ($ SQL);/* first query */$ id = 3; $ mysqli_stmt-> bind_param (" I ", $ id ); // bind_result ($ id, $ account); // bind the result set $ mysqli_stmt-> execute (); while ($ mysqli_stmt-> fetch ()) {echo "<br/> -- $ id ----- $ account";} echo "<br/> ---------------------------------";/* second query */$ id = 5; $ mysqli_stmt-> bind_param ("I", $ id); // bind data // $ mysqli_stmt-> bind_result ($ id, $ account ); // bind the result set $ mysqli_stmt-> execute (); wh Ile ($ mysqli_stmt-> fetch () {echo "<br/> -- $ id ----- $ account";} echo "<br/> ---------------------------------"; /* The third query */$ id = 6; $ mysqli_stmt-> bind_param ("I", $ id ); // bind_result ($ id, $ account); // $ mysqli_stmt-> bind_result ($ id, $ account) is bound to the result set. $ mysqli_stmt-> execute (); while ($ mysqli_stmt-> fetch () {echo "<br/> -- $ id ----- $ account" ;}$ mysqli_stmt-> close (); $ mysqli-> close ();?>


Note: It is for reference only and csdn reprinted.

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.