首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何从数据库中提取记录,调整它们并将它们插入另一列?

我如何从数据库中提取记录,调整它们并将它们插入另一列?
EN

Stack Overflow用户
提问于 2017-08-11 13:22:06
回答 1查看 38关注 0票数 0

我需要从我的数据库表(故事)中提取故事名称,将它们更改为url友好格式(“权力的游戏->权力的游戏”),并将它们插入到同一表(story.permalink)中的另一列中。有什么好办法吗?我当前从mac终端运行的php函数不起作用。

代码语言:javascript
复制
$conn = update_dao_connect();
$get_stmt = $conn->prepare("select id, name from story");
$update_stmt = $conn->prepare("update story set permalink=? where id=?");
$update_stmt->bind_param("si", $permalink, $id);
if($get_stmt->execute()){
    $get_stmt->bind_result($id, $name);
    while($get_stmt->fetch()){
        $permalink = generate_story_permalink($name);
        if(!$update_stmt->execute()){
            error_log("update permalink failed for kamp id: ".$id.", name: ".$name.", permalink: ".$permalink);
        }
    }
}
else {
    error_log("execute get all story for copy_story_names_to_permalinks fail");
}

终端输出(用于数据库中的所有记录):

更新permalink失败的故事id: 198,名称: Funding循环的故事,permalink: funding-循环-故事

更新permalink失败的事件id: 199,名称: Rentah,permalink: rentah-1

更新permalink失败的故事id: 200,名称: Kano计算,permalink: kano-计算

更新permalink失败的故事id: 201,名称:替代,permalink:替代-1

提前谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-16 10:37:42

解决方案是添加$get_stmt->store_result();在$get_stmt->execute()之后添加;如下面的答案Commands out of sync; you can't run this command now所示

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45636283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档