Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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
phpmyadmin和mysql pdo lastInsertId()_Php_Mysql_Pdo_Phpmyadmin_Lastinsertid - Fatal编程技术网

phpmyadmin和mysql pdo lastInsertId()

phpmyadmin和mysql pdo lastInsertId(),php,mysql,pdo,phpmyadmin,lastinsertid,Php,Mysql,Pdo,Phpmyadmin,Lastinsertid,我有这个 $query = "INSERT INTO players VALUES ( UUID(), :firstname, :lastname, :age, :birthplace, :height, :weight

我有这个

$query = "INSERT INTO players VALUES (
                    UUID(),
                    :firstname,
                    :lastname,
                    :age,
                    :birthplace,
                    :height,
                    :weight,
                    :bats,
                    :throws,
                    :position,
                    :jersey,
                    :status,
                    :team,
                    :image_path
                )";
    $sth = $db->prepare($query);
    $sth->execute(array(
        ':firstname' => $firstname,
        ':lastname' => $lastname,
        ':age' => $age,
        ':birthplace' => $birthplace,
        ':height' => $height,
        ':weight' => $weight,
        ':bats' => $bats,
        ':throws' => $throws,
        ':position' => $position,
        ':jersey' => $jersey,
        ':status' => $status,
        ':team' => $team,
        ':image_path' => $image_path
    ));

    $id = $db->lastInsertId();
    return $id;
我试图返回插入的最后一个ID,我得到的只是返回的0。 非常感谢您的帮助 感谢您上次插入ID(),朋友只对通过
自动增量列创建的整数ID有效。您需要运行两个查询-首先

SELECT UUID() AS newuuid;
然后获取并存储此结果(例如,在
$uuid
中),然后

留给您的
$uuid
仍然有效。

LAST\u INSERT\u ID()。您需要运行两个查询-首先

SELECT UUID() AS newuuid;
然后获取并存储此结果(例如,在
$uuid
中),然后


留给您的
$uuid
仍然有效。

首先检查执行是否成功。因为如果不是,那么0可能就是正确的,对吗?是的,执行是有效的,所有的事情都会正确地添加到数据库中。首先,检查执行是否成功。因为如果不是,那么0可能就是正确的,对吗?是的,执行有效,并且所有内容都正确添加到数据库中