我试图插入我的数据库工作正常,但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');
}
答案 0 :(得分:3)
//更改
$id = $db->lastInsertId();
到
$id = $stmt->lastInsertId();