I'm trying to 开发者_StackOverflow社区get the id of last inserted record in the Db. But i'm getting the error
Parse error: syntax error, unexpected T_RETURN in Z:\www\CI4\application\models \report_model.php on line 69
my model:
function getLastInserted() {
$query ="SELECT $id as maxID from info where $id = LAST_INSERT_ID()"
return $query; //line 69
}
my controller:
function index()
{
$id=$this->report_model->getLastInserted();
$this->load->view('u_type1',$id);
}
Assuming you are using the CI database library, you can use $this->db->insert_id()
.
function getLastInserted() {
return $this->db->insert_id();
}
I think you are missing a ;
on line 67 after the last "
.
if you want to get last id without insert function
$this->db->select('id')->order_by('id','desc')->limit(1)->get('table_name')->row('id');
精彩评论