Home > headlines > PHP database operations--data preprocessing, update, delete

PHP database operations--data preprocessing, update, delete

无忌哥哥
Release: 2018-06-27 15:08:04
Original
2830 people have browsed it

Statement preprocessing: Generally speaking, it is a query and multiple executions. It will be often used in our later projects.

Creation:

//Creation preprocessing

$createinto=$connent->prepare("insert into zh(name,age,email) values (?,?,?)");
Copy after login

sql statement, the parameters use? instead of reserved

//绑定  
$createinto->bind_param("sis",$name,$age,$email);
Copy after login

The 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();
Copy after login

Execute the statement; finally the data is inserted successfully. (The premise is to connect to the database and use)

Delete the specified entry:

mysqli_query($connent,"delete from zh where name='zhanghao1'");
Copy after login

Delete the entire table data without adding where conditions

Update the specified entry:

mysqli_query($connent,"update zh set age=3 where name='zhanghao2'");
Copy after login

Modify zhanghao2’s age to 3

Close the database after all database operations are completed.

----Complete code-------

connect_error){  
    die("连接失败: " . $connent->connect_error);  
}else{  
    echo "成功";  
  
}  
//创建预处理  
$createinto=$connent->prepare("insert into zh(name,age,email) values (?,?,?)");  
  
//绑定  
$createinto->bind_param("sis",$name,$age,$email);  
//多次执行  
$name="zhanghao1";  
$age=1;  
$email="1234123123@qq.com";  
$createinto->execute();  
  
$name="zhanghao2";  
$age=2;  
$email="1234123123@qq.com";  
$createinto->execute();  
echo "插入成功";  
  
//删除数据 删除表中 name为zhanghao1的数据  
mysqli_query($connent,"delete from zh where name='zhanghao1'");  
  
mysqli_query($connent,"update zh set age=3 where name='zhanghao2'");  
  
$connent->close();  
?>
Copy after login

We can find that where is the basis for judging conditions. According to it, we can conditionally query, Condition deletion and condition modification.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template