Both sql LAST_INSERT_ID() and PHP insert_id return 0
- by jakubplus
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.