Spidy has asked for the wisdom of the Perl Monks concerning the following question:
Recently, I've been doing some work on a MySQL system that involves, among other things, inserting rows into a certain table. In order to keep the table organized, we have it arranged like this:
id | path |
int not null auto_increment | text |
Now, this is all well and good, and it serves our purposes fine. We use the auto_increment attribute of the id column in order to track each entry within our table. To insert something, we use this query:
$sth = $dbh->prepare("INSERT INTO table(path) VALUES(?)"); $sth->execute($path);
And after this, I need to retrieve the id value for the row that we just inserted. I know this can be accomplished with a simple select query after the insertion, but I'm wondering: is there any way for me to reduce this to a single query, that will insert the row and return the id for the row that was just inserted?
Thanks,
Spidy
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: MySQL: INSERT and return?
by chromatic (Archbishop) on Jul 04, 2006 at 18:54 UTC | |
by initself (Monk) on Apr 10, 2007 at 18:52 UTC | |
Re: MySQL: INSERT and return?
by jdtoronto (Prior) on Jul 05, 2006 at 04:04 UTC |