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

PHP database operations--data preprocessing, update, delete

无忌哥哥
无忌哥哥Original
2018-06-27 15:08:042847browse

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 (?,?,?)");

sql statement, the parameters use? instead of reserved

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

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();

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'");

Delete the entire table data without adding where conditions

Update the specified entry:

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

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();  
?>

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

Statement:
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