[英]MYSQL, multiple table update
我有一个查询来更新6个表中的值,
6个表的格式相同,结构类似
ID Ref Date
21 1 26/01/2015
22 2 26/01/2015
23 3 26/01/2015
还有一张表格,其中包含一系列具有以下结构的车辆:
ID Name
1 name
2 name
3 name
因此,需要更新的6个表中的Ref列与车辆名称的ID相对应。
这是我目前有的查询,
UPDATE transport_tax, transport_tachocalibration, transport_service, transport_rbt, transport_mot, transport_ivc
SET transport_tax.Date = '$tax',
transport_tachocalibration.Date = '$tacho',
transport_service.Date = '$service',
transport_rbt.Date = '$rbt',
transport_mot.Date = '$mot',
transport_ivc.Date = '$ivc',
WHERE
transport_tax.Ref = '$id' AND
transport_tachocalibration.Ref = '$id' AND
transport_service.Ref = '$id' AND
transport_rbt.Ref = '$id' AND
transport_mot.Ref = '$id' AND
transport_ivc.Ref = '$id'
此查询在PHP中的原因就是在那里存在变量,要更新的6个值都全部等于1/1/2015,$ id等于1。当前运行此查询时,出现此错误
Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE transport_tax.Ref = '1' AND transport_tachocalibr' at line 8 in C:\wamp\www\application\models\Transport_model.php on line 76
任何帮助将非常感激,
在WHERE
之前删除逗号
transport_ivc.Date = '$ivc', WHERE
here-----------^
如果在严格模式下运行数据库,则首先删除WHERE
之前的行中的逗号,并确保查询类型的安全。 如果您使用整数或一般数字值,则不应添加刻度,例如:
transport_tax.Ref = $id AND
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.