1, using MYSQLI Extension Library preprocessing technology mysqli stmt add 3 users to the database
Copy Code code as follows:
<?php
MYSQLI Extension Library preprocessing technology mysqli stmt add 3 users to the database
1. Create Mysqli objects
$mysqli = new Mysqli ("localhost", "root", "root", "test");
if ($mysqli->connect_error) {
Die ($mysqli->conncet_error);
}
2. Create Precompiled objects
$sql = "INSERT INTO User1 (name,password,email,age) VALUES (?,?,?,?)";
$mysqli _stmt= $mysqli->prepare ($sql);
Binding parameters
$name = "Small Fang";
$password = "123456";
$email = "xiaofang@126.com";
$age = 18;
Parameter binding-> to? Number assignment here is the same type and order
$mysqli _stmt->bind_param ("SSSI", $name, $password, $email, $age);
Perform
$b = $mysqli _stmt->execute ();
Continue to add
$name = "Xiao Yang";
$password = "123456";
$email = "xiaoyang@126.com";
$age = 18;
Parameter binding-> to? Number assignment here is the same type and order
$mysqli _stmt->bind_param ("SSSI", $name, $password, $email, $age);
Perform
$b = $mysqli _stmt->execute ();
Continue to add
$name = "small g";
$password = "123456";
$email = "xiaoG@126.com";
$age = 18;
Parameter binding-> to? Number assignment here is the same type and order
$mysqli _stmt->bind_param ("SSSI", $name, $password, $email, $age);
Perform
$b = $mysqli _stmt->execute ();
if (! $b) {
Echo "Operation failed". $mysqli _stmt->error;
}else{
echo "Successful operation";
}
Turn off precompilation
$mysqli _stmt->close ();
$mysqli->close ();
?>
2, use the preprocessing query id>5 user ID name email
Copy Code code as follows:
<?php
User ID name email with preprocessing query id>5
$mysqli =new mysqli ("localhost", "root", "root", "test");
if ($mysqli->connect_error) {
Die ($mysqli->connect_error);
}
To create a precompiled object
$sql = "Select Id,name,email from User1 where Id>?";
$mysqli _stmt= $mysqli->prepare ($sql);
$id = 5;
Binding parameters
$mysqli _stmt->bind_param ("i", $id);
Binding result Sets
$mysqli _stmt->bind_result ($id, $name, $email);
Perform
$mysqli _stmt->execute ();
To remove a bound value
while ($mysqli _stmt->fetch ()) {
echo "<br/> $id--$name--$email";
}
Close Resource
Release results
$mysqli _stmt->free_result ();
Closing and compiling statements
$mysqli _stmt->close ();
Close connection
$mysqli->close ();
?>