PDO Updating multiple records(PDO 更新多条记录)
问题描述
我知道以前有人问过这个问题,我已经回答了很多问题,并且正在解决其中一个问题 现在回答,但是需要以下代码块的帮助.
I know this question has been asked before and I've gone through many of the answers and am working off one of those answers now, however need some help with the following chunk of code.
<?php
$title = $_POST['title'];
$description = $_POST['description'];
$item_name = $_POST['item_name'];
$A = count($item_name);
include ("connection.php");
try {
$set_details = "UPDATE images
SET title = :title,
description = :description,
WHERE item_name = :item_name";
$STH = $conn->prepare($set_details);
$i = 0;
while($i < $A) {
$STH->bindParam(':title', $title[$i]);
$STH->bindParam(':description', $description[$i]);
$STH->bindParam(':item_name', $item_name[$i]);
$STH->execute();
$i++;
}
}
catch(PDOException $e) {
echo "I'm sorry, but there was an error updating the database.";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
?>
我在执行时没有收到任何错误,也没有任何东西提交到 mysql 表,如果你发现了什么,请告诉我,或者如果有更好的方法来解决这个问题,你能指点我一个教程吗,我没有与 PDO 或多行更新一起工作很多.
I get no errors upon execution and nothing is submitted to the mysql table, if you spot something please let me know, or if there is a better way to go about this could you point me towards a tutorial, I haven't worked much with PDO or multiple row updates yet.
提前致谢.
致山姆:
print_r($STH->errorInfo());
输出是:
Array ( [0] => 42000 [1] => 1064 [2] => 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 item_name = '27'' at line 4 )
推荐答案
:description
后面多了一个逗号,应该是:
You have an extra comma after :description
, it should be:
"UPDATE images
SET title = :title,
description = :description
WHERE item_name = :item_name"
这篇关于PDO 更新多条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PDO 更新多条记录


基础教程推荐
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01