本文介绍了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更新多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!