如何获取上次插入的ID
$datass = array (
'object_id' => $id,
'object_type'=>$ty,
'type' => $t,
'company_id'=>$c
);
return(db_query("INSERT INTO ?:discussion ?e", $datass));
现在我需要获取最后插入的ID?我怎么做。
答案 0 :(得分:1)
查找查找最后插入的值必须为
select * from tablename order by desc id limit 0,1
此处id必须是主键
试试这个: -
db_query('select * from tablename order by desc id limit 0,1');
答案 1 :(得分:0)
您也可以使用此方法。
db_get_field('SELECT MAX(field_name) FROM ?:table_name');