5

Each and every SQL query I issue to my MySQL server creates a new (increments) CONNECTION_ID(). This happens both on my local as well as on my shared remote server.

Is this the reason behind LAST_INSERT_ID() and ROW_COUNT() resulting in 0? How to address this issue?

Originally in MySQL: LAST_INSERT_ID() returns 0

Community
  • 1
  • 1
dwelle
  • 6,894
  • 2
  • 46
  • 70
  • MySQL server doesn't have a command line. There is a separate command-line client utility that can connect to a MySQL server. Is that what you're referring to? If so, have you set a non-default [`connect_timeout`](http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html#option_mysql_connect_timeout)? – eggyal Dec 14 '12 at 16:13
  • My bad. I mean't a simple SQL query box of my `phpmyadmin`. Let me check the timeout. – dwelle Dec 14 '12 at 16:15
  • do remember that last_insert_id only works on auto incremented fields, not manually given.. – Chella Dec 14 '12 at 17:32

1 Answers1

8

By default, PersistentConnections are disabled in phpMyAdmin.

Is this the reason behind LAST_INSERT_ID() and ROW_COUNT() resulting in 0?

Yes.

How to address this issue?

Enable persistent connections:

$cfg['PersistentConnections'] = TRUE;
eggyal
  • 122,705
  • 18
  • 212
  • 237
  • Solved `LAST_INSERT_ID()`, `ROW_COUNT()` still `0` after `INSERT`. Going to further test it – dwelle Dec 14 '12 at 16:27
  • 1
    Anyway, when a phpmyadmin config file is not available (on remote shared) there is no way to get a `last_id` other than to do a `SELECT` on a table? – dwelle Dec 14 '12 at 16:38