Finally began to continue to write blog, not far away from home do not know that everyone's ticket has been bought, I hope everyone can go home for a reunion year.
This article simply tells "the title"
Statement preprocessing: Popular is a query, multiple execution, in our later projects will often use
Create:
Create preprocessing
$createinto = $connent->prepare ("insert into en (name,age,email) VALUES (?,?,?)");
SQL statements, parameter use? instead of reserved
Binding
$createinto->bind_param ("Sis", $name, $age, $email);
Binding parameter S is string type I is int type
$name = "Zhanghao1";
$age =1;
$email = "1234123123@qq.com";
$createinto->execute ();
$name = "Zhanghao2";
$age =2;
$email = "1234123123@qq.com";
$createinto->execute ();
Execution statement; Last data was inserted successfully. (Provided you connect to the database and use it)
To delete a specified entry:
Mysqli_query ($connent, "delete from en where name= ' zhanghao1 '");
Delete entire table data without a Where condition
To update the specified entry:
Mysqli_query ($connent, "update en set age=3 where name= ' Zhanghao2 '");
Change the age of Zhanghao2 to 3
Close the database after all the database operations have been completed.
----Complete code-------
<?php * * Data preprocessing Remove Update data * * To change the template for this generated file go to * window-preferences-phpecli
Pse-php-code Templates//** * pretreatment Simplification Create a method to use////First connect to the database $servername = "localhost";
$username = "root";
$userpassword = "hao542161";
$dbname = "TestDB";
$connent =new mysqli ($servername, $username, $userpassword, $dbname); if ($connent->connect_error) {die ("Connection failed:".)
$connent->connect_error);
}else{echo "Success";
//Create preprocessing $createinto = $connent->prepare ("insert into en (name,age,email) VALUES (?,?,?)");
Binding $createinto->bind_param ("Sis", $name, $age, $email);
Multiple execution $name = "Zhanghao1";
$age = 1;
$email = "1234123123@qq.com";
$createinto->execute ();
$name = "Zhanghao2";
$age = 2;
$email = "1234123123@qq.com";
$createinto->execute ();
echo "Insert Success";
Deletes data from the Data deletion table named Zhanghao1 mysqli_query ($connent, "delete from en where name= ' zhanghao1 '");
Mysqli_query ($connent, "update en set age=3 where name= ' Zhanghao2 '"); $connent->close ();?>
We can find that where is the basis for judging conditions, according to which we can conditionally query, conditional deletion and conditional modification.