PHP代码中的SQL语法错误 - 将两个值相加

时间:2016-11-10 20:48:20

标签: mysql sql

我在PHP文件中的MySQL代码中不断出现此语法错误。我只是尝试使用此时间变量增加/添加表中已有的值。如果有人能帮助我,我会非常感激。

PHP:

$sql = "UPDATE Aircraft
SET MaintenanceFlightTime = (MaintenanceFlightTime + $MaintenanceDuration),
WHERE AircraftID = $AircraftID";

错误:

UPDATE Aircraft SET MaintenanceFlightTime = (MaintenanceFlightTime + 00:10:00), WHERE AircraftID = 8
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':10:00), WHERE AircraftID = 8' at line 2

1 个答案:

答案 0 :(得分:0)

您不能只将“01:01:01”这样的字符串添加到时间列,但可以使用ADDTIME()

$MaintenanceDuration = '00:10:00';

$sql = "UPDATE Aircraft
        SET MaintenanceFlightTime = ADDTIME(MaintenanceFlightTime, '$MaintenanceDuration')
        WHERE AircraftID = $AircraftID";