2017-08-11 90 views
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

謝謝我前進!

+0

如果你不能執行,你還應該記錄['mysqli_stmt_error()']返回的值(http://php.net/manual/en/mysqli-stmt.error .php) – Qirel

+0

謝謝,我在if(!$ update_stmt-> execute()){行後添加了error_log($ conn-> error),它給了我:「命令不同步;現在不能運行此命令「 –

+0

這意味着你(很可能)必須在運行新語句之前關閉前面的語句。 – Qirel

回答

相關問題