Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取插入查询的最后一个ID_Php_Mysql_Insert_Mysql Insert Id - Fatal编程技术网

Php 获取插入查询的最后一个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 (

我需要从上一个插页中获取故事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 (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