Get the id of current mysql insert

mysql, php

Solution

i use `mysql_insert_id()` for that. it works fine.

// pseudo-ish code
$query = "INSERT something .... "
$updated = $db->run_query($query);
$id = mysql_insert_id();

Problem

is there anyway to get the ID of the current record I am INSERTING into the database table using php with Mysql without having to do an extra select to get the last ID? FOr example, if my table has these columns, id, url, name and if url consists of the domain name and current id as the query variable ex: domainname.com/page.php?id=current_id ``` $sql="INSERT INTO Persons (id, url, name ) VALUES ('domainname.com/page.php?id=".**whats_the_current_id**."','$_POST[age]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ```

Original source

Related problems