本文介绍了如何在PHP中执行这两个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Stackoverflow和noob的新程序。
I am new in Stackoverflow and noob in programming.
我有一个问题。我创建了一个脚本,可以通过给数据库用户名和密码更改数据库列信息。
I have a problem . I am creating a script that can change a database column info by give database username and password.
我的源代码在这里:
<?php
$servername = "localhost";
$username = "admin";
$dbname = "mydb";
$password = "1234";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
mysqli_select_db($conn,"$dbname");
$sql = "UPDATE users SET login='admin1' WHERE id=1";
$sql2 = "UPDATE users SET pass='1234' WHERE id=1";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
现在有两个查询
$sql = "UPDATE users SET login='admin1' WHERE id=1";
$sql2 = "UPDATE users SET pass='1234' WHERE id=1";
如何执行这两个查询,我想要这两个查询成为真我消息将是显示记录已成功更新。上述源代码显示错误。
How can I execute this two query's and i want that when this two query's became true I message will be show that Record updated successfully. In the above source code showing error.
推荐答案
您可以通过一个查询更新这两个记录:
You can update both records by one query:
$sql = "UPDATE users
SET login = 'admin1',
pass = '1234'
WHERE id = 1";
这篇关于如何在PHP中执行这两个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!