我有一个问题。我似乎无法从我的 MySQL 数据库/表中获取最后插入的记录/ID。我想从“tag_id”列返回最后插入的 id,但我什么也没有得到。顺便说一句,我正在使用 DBO。我尝试了“mysql_insert_id”和“lastInsertId”,但没有成功。
我的数据库表如下所示:
表名:gitags_tags
tag_id | name
----------+---------
437 | 2011
438 | 2012
439 | 2013
440 | new
我的 PHP 看起来像这样(在这种情况下,我想返回 '440'):
/*
* Insert the new tagname in the database in the table 'gitags_tags'
*/
$query = "INSERT INTO gitags_tags (`name`) VALUES ('".$new_tagname."')";
$db->setQuery($query);
if (!$db->query()) {
echo "Something went wrong \n";
echo $query . "\n";
exit;
}
// Neither of these two work ...
echo mysql_insert_id();
echo $db->lastInsertId('tag_id');
任何帮助深表感谢。