What is pre-compilation?
For example, if you want to add records of 100 users to the database,
The method is as follows: 1. Use the For Loop
2. Use Batch Processing Technology
The principle of SQL statement execution is: the PHP program sends the SQL statement to the database, then the database compiles the statement, and then continues the operation.
In order to reduce the Compilation Time, the pre-compilation technology emerged. Pre-compilation is performed in the database, and the same insert statement is only compiled once in the database. The PHP program is used to transmit data to the database.
Case:
<? PHP // 1. create a mysqli object $ mysqli = new mysqli ("localhost", "root", "root", "test"); $ SQL = "insert into account (balance) values (?) "; // 2. create a pre-compiled object $ mysqli_stmt = $ mysqli-> prepare ($ SQL) or die ($ mysql-> error); // 3. bind the parameter $ balance = 1000; // 4. parameter binding --> assign a value to the question mark $ mysqli_stmt-> bind_param ("I", $ balance); // 5. run $ B = $ mysqli_stmt-> execute (); // Add another // 3. bind the parameter $ balance = 2000; // 4. parameter binding --> assign a value to the question mark $ mysqli_stmt-> bind_param ("I", $ balance); // 5. run $ B = $ mysqli_stmt-> execute (); // Add another // 3. bind the parameter $ balance = 2000; // 4. parameter binding --> assign a value to the question mark $ mysqli_stmt-> bind_param ("I", $ balance); // 5 . Execute $ B = $ mysqli_stmt-> execute (); If (! $ B) {die ("operation failed! ". $ Mysqli-> error);} else {echo" OKK ";} // release $ mysqli-> close ();?>