Introduction to PHP Pre-compilation processing technology

Source: Internet
Author: User

1. Improve the efficiency of the database: reduce the number of compilations, and reduce the number of connections. When an equivalent operation SQL statement, such as a large number of data into the database, the original type of execution of SQL statements or bulk execution of SQL statements, it is obviously not feasible, because whether it is a single execution or bulk execution will be continuous send SQL statements to the database, The database is compiled with SQL statements, resulting in efficiency. The pre-compilation that appears in PHP solves this problem, and he works by sending SQL statements to the database to pre-compile the SQL statement. Then you just need to send the data to the database.

2. Here is an example of what I am learning as an illustration:

<?php
Precompiling not only improves efficiency, it also prevents SQL injection attacks
$mysqli =new mysqli ("localhost", "root", "root", "test303");
if ($mysqli->connect_error) {
Die ("Connection failed! ". $mysqli->connect_error);
}
1. Pre-compile objects for wearing pieces
$sql = "INSERT into account values (?,?);";
$mysqli _stmt= $mysqli->prepare ($sql);//$mysqli->prepare prepare to execute SQL statement
2. Binding parameters
$id = 4;
$account = 400;
3. Assign the value of the binding to? , the type should always
$mysqli _stmt->bind_param ("II", $id, $account); A binding variable comes as a parameter in a declaration
4. Implementation
$res = $mysqli _stmt->execute ();//execute the prepared query
if (! $res) {
Die ("Operation failed". $mysqli _stmt->error);
}else {
echo "Operation succeeded! ";
}
5. Releasing Resources
$mysqli->close ();
?>

3. Data Sheet

CREATE TABLE Acount (

ID int PRIMARY KEY,

account int

);

Introduction to PHP Pre-compilation processing 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.