使用pdo更新内连接查询

时间:2015-07-20 10:38:46

标签: php pdo

我正在尝试使用内部联接更新两个表,但是它没有更新或者都没有显示任何错误。这是代码

$id_prod = 2;
$id_cust = 2;
$sql5 = "UPDATE `customer` 
           INNER JOIN `products` ON products.cust_id=customer.id 
         SET prod_name = 'CAKE' AND name = 'Hassan' 
         WHERE id='$id_cust' AND id='id_prod' ";
$query5 = $conn->prepare($sql5);
$query5->execute(array($id_cust, $id_prod));

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

也许要设置的列名称错误,如果在列名前加上表名,那会更好吗?

像这样:

$id_prod = 2;
$id_cust = 2;
$sql5 = "UPDATE `customer` 
           INNER JOIN `products` ON products.cust_id=customer.id 
         SET __tableName__.prod_name = 'CAKE' AND __tableName__.name = 'Hassan' 
         WHERE __tableName__.id='$id_cust' AND __tableName__.id='id_prod' ";
$query5 = $conn->prepare($sql5);
$query5->execute(array($id_cust, $id_prod));