【发布时间】:2015-10-08 07:27:24
【问题描述】:
我编写了在 MySql 表中插入新记录的代码。有什么方法可以让我在不进行新查询的情况下获得插入的行id?
try {
$NEWData = $DBH->prepare("
INSERT INTO boge
(name, grade, school, made, type)
VALUES (:name, :grade, :school, NOW(), '2')"
);
$NEWData->bindParam(':name', $navn); // Erik
$NEWData->bindParam(':grade', $skid); // 12
$NEWData->bindParam(':school', $klasseId); // 1 - school have an id
// wants to get the new rows id
$NEWData->execute();
} catch(PDOException $e) {
echo $e->getMessage();
exit();
}
【问题讨论】:
-
$DBH->lastInsertId()