2

我需要从最后一个插入中获取 story_id。我试过使用mysql_insert_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();
4

1 回答 1

5

如果您使用的是 PDO,以下是如何获得它

PDO::lastInsertId()

如果使用 mysqli,试试这个

mysqli::$insert_id
于 2012-06-12T15:46:30.930 回答