Principle of thinking
The code is as follows:
1<?PHP2 //Pre-compiled demo3 //requirements: Use preprocessing to add three users to a database4 //1. Creating a Mysqli Object5 $mysqli=NewMysqli ("localhost", "root", "hsp123", "Test");6 //2. Creating Precompiled Objects7 $sql = "INSERT INTO User1 (name,password,email,age) VALUES (?,?,?,?)";8 $mysqli _stmt= $mysqli->prepare ($sql) or Die ($mysqli->error);9 //Binding ParametersTen $name= "Xiao Qian"; One $password= "Xiaoqian"; A $email= "[Email protected]"; - $age= "200"; - //parameter binding, assign value, here the type and order are to correspond. the // - $mysqli _stmt->bind_param ("SSSI", $name, $password, $email, $age); - //Execution - $b = $mysqli _stmt->execute (); + - //continue to add + $name= "Old Demon"; A $password= "Laoyao"; at $email= "[Email protected]"; - $age= "210"; - $mysqli _stmt->bind_param ("SSSI",$name,$password,$email,$age); - //Execution - $b=$mysqli _stmt-execute (); - in //continue to add - $name= "Vegetable Layer"; to $password= "AAA"; + $email= "[Email protected]"; - $age= "30"; the $mysqli _stmt->bind_param ("SSSI",$name,$password,$email,$age); * //Execution $ $b=$mysqli _stmt-execute ();Panax Notoginseng if(!$b){ - die("Operation failed".)$mysqli _stmt-error); the}Else{ + Echo"Operation OK"; A } the //Release + $mysqli-close (); -?>
Preprocessing technology of Mysqli extended library mysqli stmt