Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using INSERT to create row. how do i get # value of auto increment...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034

i have a table that has a column that is using auto_increment, and also is the primary key for table. i am creating new rows using:

[code}
$dbh9 = DBI->connect('dbi:mysql:gtc','','');
$sth9 = $dbh9->prepare("INSERT INTO orders VALUES(0,'$actualCart')");
$sth9->execute;
[/code]

no problem. however, i need to retrieve the new number value assigned once that row is created. how do i do that? (just short of having another unique identifier and searching for that, then getting the number of row)

any ideas?

- g
 

so, like this?

Code:
$dbh99 = DBI->connect('dbi:mysql:gtc','','');
$sth99 = $dbh99->prepare("SELECT LAST_INSERT_ID()");
$sth99->execute;

how do i retrieve the result?

- g
 
i'm assuming you are using php couldn't you do something like this

Code:
$dbh9 = DBI->connect('dbi:mysql:gtc','','');
$sth9 = $dbh9->prepare("INSERT INTO orders VALUES (0,'$actualCart')");
$orderID = mysql_insert_id()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top