PHP PDO 不会更新数据库

标签 php mysql pdo sql-update

我尝试使用 PDO,但结果为 1,1,1,但数据库不会更新。我不知道我的代码有什么问题。

try {$db = new PDO("mysql:dbname=$db_name;host=$db_host", $db_user, $db_pass );}
catch(PDOException $e){echo $e->getMessage();}

$title_insert = $db->prepare("UPDATE topics SET topic_title = ? WHERE id = ?");
$title_insert->bindParam(1, $id);
$title_insert->bindParam(2, $topic_title);

$tag_insert = $db->prepare("UPDATE topics SET topic_tags = ? WHERE id = ?");
$tag_insert->bindParam(1, $id);
$tag_insert->bindParam(2, $topic_tags);

$story_insert = $db->prepare("UPDATE topics SET topic_story = ? WHERE id = ?");
$story_insert->bindParam(1, $id);
$story_insert->bindParam(2, $topic_story);


$id = 1;
$topic_title = "title";
$topic_tags = "tags";
$topic_story = "story";

$result_title = $title_insert->execute();
echo $sonuc_title.',';

$sonuc_tag = $tag_insert->execute();
echo $sonuc_tag.',';

$result_story = $story_insert->execute();
echo $result_story;

感谢您的回答...

最佳答案

您是否尝试过切换参数编号?

$title_insert = $db->prepare("UPDATE topics SET topic_title = ? WHERE id = ?");
$title_insert->bindParam(1, $topic_title);
$title_insert->bindParam(2, $id);

祝你好运!

PDO Bind param

关于PHP PDO 不会更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20994310/

相关文章:

php - 为什么这个 PDO 语句会默默地失败?

php - jQuery AJAX 发布到 PHP 的 PDO INSERT 不使用变量 $ ('#id').val()

php - HTML 按钮在 Wordpress 中无法在移动设备上运行

php - PDO 交互在类之间共享

mysql准备语句在执行stmt时没有重复变量使用

c# - 将 MySQL 与 Visual Studio 结合使用 (c#)

mysql 查询 : How can I group by only cpm. ad_id 并拥有所有 cc 的总和?

php - SoapServer 发送没有信封的响应

javascript - 大型 sql 表 - 选择所有但使用 javascript/PHP 逐步显示

php - 使用 PDO 获取 MySQL 服务器版本