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.