This article shares the PHP use mysqli Extension Library for preprocessing operations of two examples, interested in studying the use of mysqli friends, you can refer to the study, will certainly be helpful. Example 1, preprocessing technology using MYSQLI Extension Library mysqli stmt add 3 users to a database
Connect_error) {die ($mysqli->conncet_error);} 2. Create precompiled object $sql= "insert into User1 (name,password,email,age) VALUES (?,?,?,?)"; $mysqli _stmt= $mysqli->prepare ($sql);//binding parameter Bbs.it-home.org$name= "Small Fang";//$password =md5 ("ffff"); $password = " 123456 "; $email =" xiaofang@jbxue.com "; $age =18;//parameter binding? The type and order of the number should be consistent $mysqli_stmt->bind_param ("SSSI", $name, $password, $email, $age);//execute $b= $mysqli _stmt->execute () ;//Continue to add $name= "Xiao Yang"; $password = "123456"; $email = "xiaoyang@jbxue.com"; $age =18;//parameter binding? The type and order of the number should be consistent $mysqli_stmt->bind_param ("SSSI", $name, $password, $email, $age);//execute $b= $mysqli _stmt->execute () ;//Continue to add $name= "small g"; $password = "123456"; $email = "xiaoG@jbxue.com"; $age =18;//parameter binding? The type and order of the number should be consistent $mysqli_stmt->bind_param ("SSSI", $name, $password, $email, $age);//execute $b= $mysqli _stmt->execute () if (! $b) {echo "operation failed". $mysqli _stmt->error;} Else{echo "Operation succeeded";} Turn off precompiled $mysqli_stmt->close (); $mysqli->close ();? > Example 2, using pre-processing query id>5 User ID name email
The user ID of 5 is name email$mysqli=new mysqli ("localhost", "root", "root", "test"), if ($mysqli->connect_error) {die ($mysqli- >connect_error);} Create precompiled Object $sql= "select Id,name,email from User1 where Id>?"; $mysqli _stmt= $mysqli->prepare ($sql) $id =5;//binding parameter $mysqli_stmt->bind_param ("I", $id);//bind result set $mysqli_stmt- >bind_result ($id, $name, $email);//execute $mysqli_stmt->execute ();//Remove the bound value while ($mysqli _stmt->fetch ()) {echo " $id--$name--$email ";} Close resource//release result $mysqli_stmt->free_result ();//close with compile statement $mysqli_stmt->close ();//close connection $mysqli->close (); >
|