PHP Database Operations-Data preprocessing, UPDATE, delete __ Database

Source: Internet
Author: User

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.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.