How to get the value of the latest auto-incremented value on a mysql table with concurrent connections

Reading Time: < 1 minute

When building a web application it can seem a bit tricky to get the value of the id (primary key) of the latest row inserted in a mysql table.

It is not that complicated.

The function LAST_INSERT_ID() can help you finding that. This function will return the latest auto-incremented value. No need to specify the table, it just takes the latest one.

SELECT LAST_INSERT_ID() ;

The next question is: what happens when I have many concurrent sessions on the same server? Will I get the latest inserted id from another user?

Modify the session timeout in phpmyadmin

Reading Time: < 1 minute

Login and re-login and re-re-login in phpmyadmin is a huge pain.

Here is the way to extend sessions duration.

Open the file config.inc.php in /usr/share/phpmyadmin or in /etc/phpmyadmin

Add the following line:

$cfg['LoginCookieValidity']=86400;

And in php.ini, modify the following line:

session.gc_maxlifetime = 86400

Restart apache.

apache2ctl restart

You now have 24h sessions.