Php-pre-compilation

Source: Internet
Author: User
Php-pre-compilation when an equivalent SQL statement occurs, such as inserting a large amount of data into the database, the original practice of executing a single SQL statement or executing SQL statements in batches is obviously not feasible, whether it is a single execution or batch execution, an SQL statement is sent continuously to the database, and the database receives an SQL statement to compile and process it, resulting in lower efficiency.

The pre-compilation in php solves this problem. its working principle is: sending the SQL statement, and the database will pre-compile the SQL statement. Then you only need to send the data to the database.

The following is an official example to illustrate this situation:

 prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
$stmt->bind_param('sssd', $code, $language, $official, $percent);$code = 'DEU';$language = 'Bavarian';$official = "F";$percent = 11.2;/* execute prepared statement */$stmt->execute();printf("%d Row inserted.\n", $stmt->affected_rows);/* close statement and connection */$stmt->close();/* Clean up table CountryLanguage */$mysqli->query("DELETE FROM CountryLanguage WHERE Language='Bavarian'");printf("%d Row deleted.\n", $mysqli->affected_rows);/* close connection */$mysqli->close();?> 


$ Mysqli-> prepare is used to pre-compile SQL statements,

$ Stmt-> bind_param is used to bind parameters.

$ Stmt-> execute (); is an insert operation.

To insert multiple data, you only need to operate $ stmt-> bind_param and $ stmt-> execute.

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.