Both sql LAST_INSERT_ID() and PHP insert_id return 0

Posted by jakubplus on Stack Overflow See other posts from Stack Overflow or by jakubplus
Published on 2013-11-02T09:45:41Z Indexed on 2013/11/02 9:53 UTC
Read the original article Hit count: 123

Filed under:
|
|
|
|

I've been searching google a lot for this issue and really found nothing. People just keep copying MySQL documentation on last_insert_id and nothing else.

I've got an issue regarding last_insert_id, because for both situations (php & sql) it returns 0.

YES: I've set a PRIMARY & UNIQUE field with AUTO_INCREMENT value YES: i've done some inserting before NO: Making double query with INSERT AND SELECT LAST... doesn't work.

I've created a class Db for maintaining connection & query:

class Db
{
    public function connect() { 
    $db = new mysqli('','','','',''); ... return $db; }

    public function insert() { 
    $this->connect()->query("INSERT INTO bla bla..."); return $this->connect()->insert_id; }
}

And it doesn't work.

© Stack Overflow or respective owner

Related posts about php

Related posts about sql