I have 2 database connections, and I want to get the last inserted ID from one of the connections.
$old_database = mysql_connect('host', 'username', 'password');
mysql_select_db('database1', $old_database);
$new_database = mysql_connect('host', 'username', 'password',true);
mysql_select_db('database2', $new_database);
$sql=mysql_query("INSERT INTO `table1`",$new_database);
$newid = mysql_insert_id();
Do I need to specify anything in the mysql_insert_id() function? I've been running into retrieving the last known ID, and I think it's due to this.
Yes you need to specify the MySQL Resource Link Identifier, see: https://www.php.net/manual/en/function.mysql-insert-id.php
Like this:
$sql = mysql_query("INSERT INTO `table1`",$new_database);
$newid = mysql_insert_id($new_database);