我需要從最後一個插入中獲取story_id。我試過使用mysql_insert_id()
,但它似乎不適用於我的聲明。下面是代碼:獲取插入查詢的最後一個ID
$stmt = $this->db->prepare("INSERT INTO active_stories (story_id, current_chapter, creator, cover_title, cover_img_name, create_date, last_update_date, story_tags, locked) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("issssssi",$zero, $creatorName,$storyTitle, $fileName, $createDate, $createDate, $themeTags, $zero);
$stmt->execute();
printf("Last inserted record has id %d\n", mysql_insert_id());
$stmt->close();
同樣的問題在這裏問。 http://stackoverflow.com/questions/5057954/get-last-insert-id-after-a-prepared-insert-with-pdo – ExtremelyPoorMan
謝謝,我試圖尋找這個,但不知道它當我做'$ storyID = $ db-> lastInsertId('story_id')時,我被稱爲PDO – mkral