获得最后插入的记录/ ID我有一个问题。我似乎无法从我的MySQL数据库/表中获取最后插入的记录/ ID。我想从'tag_id'列中返回最后一个插入的id,但我没有收到任何回应。顺便说一句,我正在使用DBO。我尝试了'mysql_insert_id'和'lastInsertId',但没有成功。我似乎无法从MySQL
我的数据库表看起来像这样:
表名: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');
任何帮助深表感谢。
它必须是一个Joomla的问题。请[*阅读此*](http://www.webmasterworld.com/php/3600870.htm)。 –
如果你想从数据库中获取数据,请出示你'select'查询,而不是你的'insert'查询。使用Joomla标准阅读关于编码数据库查询的Joomla文档! http://docs.joomla.org/Selecting_data_using_JDatabase .... ....和http://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase – Lodder
试试这个的var_dump($ DB-> mysql_insert_id()); –