0
当我们尝试更新时,会显示所有输出(“成功步骤”)1,2,4,5。但是当我们试图检查数据库时,只有第一个数据库能够进行更新。更新只发生在第一个数据库中,而不发生在第二个数据库
$host = "172.16.1.16";
$user = "root";
$password = "root";
$dbname1 = "nocs";
$dbname2 = "nocs_backup";
这是第一个数据库
$db1 = new mysqli($host, $user, $password, $dbname1);
if($db1->connect_errno > 0){
die('Unable to connect to database' . $db1->connect_error);
}
else
{
$updateComponentSql = "UPDATE component
SET `Component_name`='$name', `Brand`='$brand',
`Model`='$model', `Type`='$type',
`Capacity`='$capacity',`Serial_no`='$serial',
`Description`='Installed'
WHERE `Component_id`='$d_id'
AND `computer_id`='$c_id'";
if (mysqli_query($db1, $updateComponentSql))
{
echo "<script type='text/javascript'>
alert('Succesful step 1');
</script>";
}
这里是第二
$db2 = mysqli_connect($host, $user, $password, $dbname2);
echo "<script type='text/javascript'>alert('Succesful step 2');</script>";
if($db2->connect_errno > 0)
{
die('Unable to connect to database' . $db2->connect_error);
echo "<script type='text/javascript'>alert('Successful step 3');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Succesful step 4');</script>";
if (mysqli_query($db2, "UPDATE component
SET (`Component_name`='$name',
`Brand`='$brand', `Model`='$model',
`Type`='$type',`Capacity`='$capacity',
`Serial_no`='$serial',
`Description`='Installed'
WHERE `Component_id`='$d_id'
AND `computer_id`='$c_id)"))
{
echo "<script type='text/javascript'>
alert('Succesful step 5');
</script>";
}
}
}
我们在我们束手无策。请大家帮忙:(
你的第二个'UPDATE'有语法错误。摆脱括号。 – Barmar
检查'mysqli_affected_rows($ DB2)'也许根本没有匹配的记录,也可以在某个地方打印实际的查询(如果必须的话,最好是在浏览器中),也许这些参数与你期望的不同。 com/doc/refman/5.1/en/query-log.html – VolkerK
btw:'所有的输出(“成功的步骤”)1,2,4,5都显示出来了 - 你确定显示了第5步的提示?因为正如你指出的那样,在你的查询和mysqli_qu中有一个错误ery()shold从来没有在这一个上返回true。 – VolkerK