我正在尝试将其插入数据库,但工作正常,但LastInsertId始终显示为0,有什么想法吗?
$stmt = $db->prepare('INSERT INTO players_results (matchweek_id, matchweek, game_id, username, homeresult, awayresult, goals, submit, matchweek_session) Values (:matchweekid, :matchweek, :gameid, :username, :homeresult, :awayresult, :goals, :submit, :matchweeksession)');
for ($gi = 1; $gi <= 10; $gi++) {
$stmt->execute(array(
':matchweekid' => '1',
':matchweek' => 'Matchweek 1',
':gameid' => $gi,
':username' => $_POST['username'],
':homeresult' => NULL,
':awayresult' => NULL,
':goals' => NULL,
':submit' => 'n',
':matchweeksession' => 'open'
));
$id = $db->lastInsertId('member_id');
}
最佳答案
//更改
$id = $db->lastInsertId();
至
$id = $stmt->lastInsertId();
关于php - lastInsertId = 0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45590286/