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可能就是正确的,对吗?是的,执行有效,并且所有内容都正确添加到数据库中