Php 获取插入查询的最后一个ID
我需要从上一个插页中获取故事id。我试过使用mysql\u insert\u id(),但它似乎对我的语句不起作用。代码如下:Php 获取插入查询的最后一个ID,php,mysql,insert,mysql-insert-id,Php,Mysql,Insert,Mysql Insert Id,我需要从上一个插页中获取故事id。我试过使用mysql\u insert\u 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 (
$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();
如果您正在使用PDO,则:
如果使用mysqli,则:
这里也有同样的问题。谢谢,我试图搜索这个,但当我搜索时不知道它被称为pdo,
$storyID=$db->lastInsertId('story_id')
我得到以下错误:调用非对象上的成员函数lastInsertId()
使用$this->db->lastInsertId('story_id')代码>嗯,我想我使用的是mysqli而不是PDO。如果是这样的话,那么你就会想看到:我找到了,它的$stmt->insert\id代码>用于mysqli。你给我指出了正确的方向,谢谢!
PDO::lastInsertId()
mysqli::$insert_id