【发布时间】:2012-06-07 15:09:38
【问题描述】:
我有这个
$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。 任何帮助是极大的赞赏 谢谢
【问题讨论】:
-
首先检查是否执行成功。因为如果不是,那么 0 可能就是正确的,对吧?
-
是的,执行正常,一切正常,行被正确添加到数据库中
标签: php mysql pdo phpmyadmin lastinsertid