由于表名与变量绑定,下面的pdo update语句不起作用。有谁知道如何让它发挥作用?
$stmt1 = $DB_CON_C->prepare('UPDATE `".$account_list."`
SET property_type=:property_type; property_address=:property_address, property_city=:property_city, property_state=:property_state, property_zip=:property_zip WHERE contract_number=:order_list');
$stmt1->bindParam(':account_list', $account_list, PDO::PARAM_STR);
$stmt1->bindParam(':order_list', $order_list, PDO::PARAM_STR);
$stmt1->bindParam(':property_class', $property_class, PDO::PARAM_STR);
$stmt1->bindParam(':property_type', $property_type, PDO::PARAM_STR);
$stmt1->bindParam(':property_address', $property_address, PDO::PARAM_STR);
$stmt1->bindParam(':property_city', $property_city, PDO::PARAM_STR);
$stmt1->bindParam(':property_state', $property_state, PDO::PARAM_STR);
$stmt1->bindParam(':property_zip', $property_zip, PDO::PARAM_STR);
$stmt1->execute();
答案 0 :(得分:2)
您必须使用单引号而不是双引号:
$stmt1 = $DB_CON_C->prepare('UPDATE `' .$account_list. '`
SET property_type=:property_type; property_address=:property_address, property_city=:property_city, property_state=:property_state, property_zip=:property_zip WHERE contract_number=:order_list');
答案 1 :(得分:1)
或者,只需简化,然后执行:
->prepare("UPDATE {$account_list} SET...
即,使用双引号。不需要{}
,但我更喜欢使用它们,因为我个人使用它作为实际表名的前缀(所以("SELECT * FROM {$dbprefix}tablename")
)
这样您就不需要在查询中编写字符串,这是您不应该做的。只需用双引号括起查询。