我需要从我的数据库表(故事)中提取故事名称,将它们更改为url友好格式(“权力的游戏->权力的游戏”),并将它们插入到同一表(story.permalink)中的另一列中。有什么好办法吗?我当前从mac终端运行的php函数不起作用。
$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
提前谢谢你!
发布于 2017-08-16 10:37:42
解决方案是添加$get_stmt->store_result();在$get_stmt->execute()之后添加;如下面的答案Commands out of sync; you can't run this command now所示
https://stackoverflow.com/questions/45636283
复制相似问题