簡體   English   中英

MYSQL,多表更新

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM