0
我需要从我的数据库表(故事)中拉出故事名称,将它们更改为友好格式(权力游戏 - >权力游戏),并将它们插入同一表中的不同列(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");
}
端子输出(用于数据库中的所有记录):
更新固定链接失败的故事ID:198,名称:资金圈的故事,永久链接:资金,圆楼的
更新固定链接失败的故事ID: 199,名称:Rentah,permalink:rentah-1
更新固定链接失败故事编号:200,名称:卡诺计算,永久链接:卡诺计算
更新固定链接失败故事编号:201,名称:替补,永久链接:置换-1
谢谢我前进!
如果你不能执行,你还应该记录['mysqli_stmt_error()']返回的值(http://php.net/manual/en/mysqli-stmt.error .php) – Qirel
谢谢,我在if(!$ update_stmt-> execute()){行后添加了error_log($ conn-> error),它给了我:“命令不同步;现在不能运行此命令“ –
这意味着你(很可能)必须在运行新语句之前关闭前面的语句。 – Qirel