Re: Related Tables - Capture ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



$sql = "insert into table2(fld,fld2)values( 2, 4)";
$db->query($sql);
$new_id = $db->query('select last_insert_id');

$sql = "insert into table3(table2_id, fld) values($new_id,3)"
$db->query($sql);

the altenative syntax for the secound query could also be
$sql = "insert into table3(table2_id, fld) values(last_insert_id() ,3)"

hop it helps
Pete


Marie Osypian wrote:
Hello,

I have three table in which I am inserting records into in one script.  I
need to capture the ID of the second tables record insertion to insert into
a field into a related table in the third.  What would the easiest way to go
about this in php?

Thanks,

MAO




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux