0

I have a table that has a primary key that autoincrements. Everytime I insert a row to that table, and use mysql_insert_id() to get the last id inserted for that table, it returns 0.

What other possible problems could there be?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user1664427
  • 237
  • 4
  • 12

1 Answers1

4

Use the method that OpenCart provides:

$this->db->getLastId()
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jay Gilford
  • 15,141
  • 5
  • 37
  • 56
  • ya i used that originally, but it was getting the same error i described above. – user1664427 Sep 20 '12 at 01:19
  • And you were using INSERT and the $this->db->query function? Also, does this issue occur when you insert a new product/category? If not, then it's either db design or you are simply not using the methods correctly. As pointed out by others a code sample would be easy enough to validate this – Jay Gilford Sep 20 '12 at 02:00