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.

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.