我想只更新数据库中的一列,但由于某种原因,我的mysql查询也更新了另一列。更新列表中未提及的时间戳列的查询
我的代码看起来有点像这样:
$sql = "UPDATE rackusage set totalDuration =".$timeDiff." where (rackID = '".$rackID."' and startTime LIKE '%".$getStartTime."%');";
echo "<br>";
echo $sql;
echo "<br>";
$res = mysql_query($sql);
这是在PHP。 我只想更新总持续时间列,但出于某种原因,startTime列也会更新。 输出字符串看起来是这样的:
UPDATE rackusage set totalDuration =30 where (rackID = '2' and startTime
LIKE '%2017-05-30 18:34:36%');
这是产生数据库:
请用准备好的语句,并且不使用MySQL的' '功能。使用MYSQLi或PDO – Akintunde007
为什么你有where子句的括号? – Akintunde007
您的图像不支持您的问题。但除startTime(不必要)上的通配符外,查询看起来是正确的。 – aynber