1

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.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
coffeemonitor
  • 12,780
  • 34
  • 99
  • 149

1 Answers1

3

Yes you need to specify the MySQL Resource Link Identifier, see: http://us2.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);
bimbom22
  • 4,510
  • 2
  • 31
  • 46