我在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

最佳答案

您不能只将'01:01:01'之类的字符串添加到时间列,而是可以使用ADDTIME()

$MaintenanceDuration = '00:10:00';

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

07-24 14:35