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