开发者

Getting the id of last inserted record

开发者 https://www.devze.com 2023-04-06 03:17 出处:网络
I\'m trying to 开发者_StackOverflow社区get the id of last inserted record in the Db. But i\'m getting the error

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号