多个UPDATE表pdo php mqsql

时间:2015-05-21 03:51:19

标签: php mysql pdo

我从this 问题的Ifran回答中得出了这个想法。但是我得到了这个#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 任何建议表示赞赏

$stmt9 = $dbh - > prepare("UPDATE student_info AS t1 ,
                                student_address AS t2 ,
                                student_course AS t3 ,
                                student_parentinfo AS t4,
                                student_references AS t5 ,
                                student_status AS t6 
                            SET t1.status = :status, 
                                t2.status = :status,
                                t3.status = :status,
                                t4.status = :status,
                                t5.status = :status,
                                t6.status = :status 
                            WHERE t1.pin = :pin,
                                t2.pin = :pin,
                                t3.pin = :pin,
                                t4.pin = :pin,
                                t5.pin = :pin,
                                t6.pin = :pin 
                            AND t1.status = :active,
                                t2.status = :active,
                                t3.status = :active,
                                t4.status = :active,
                                t5.status = :active,
                                t6.status = :active");

$stmt9 - > execute(array(':status' => $notactive, ':pin' => $pin, ':active' => $propertystatus));

更新了代码。小姐看了一些变数

1 个答案:

答案 0 :(得分:1)

将WHERE子句中的所有逗号更改为AND

$stmt9 = $dbh - > prepare("UPDATE student_info AS t1 ,
                                student_address AS t2 ,
                                student_course AS t3 ,
                                student_parentinfo AS t4,
                                student_references AS t5 ,
                                student_status AS t6 
                            SET t1.status = :status, 
                                t2.status = :status,
                                t3.status = :status,
                                t4.status = :status,
                                t5.status = :status,
                                t6.status = :status 
                            WHERE t1.pin = :pin AND
                                t2.pin = :pin AND
                                t3.pin = :pin AND
                                t4.pin = :pin AND
                                t5.pin = :pin AND
                                t6.pin = :pin
                            AND t1.status = :active AND
                                t2.status = :active AND
                                t3.status = :active AND
                                t4.status = :active AND
                                t5.status = :active AND
                                t6.status = :active");

此外,在您的execute来电中,您有:id,但未在查询中使用,但没有:pin,这是必需的。