Sorry for all those local disk links and other junk. Cut and paste.
Erik
Erik Weber wrote:
<mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.2&filename=Getting_unique_ID>
You use MySQL's AUTO_INCREMENT function (then omit the value
during an insert and MySQL will insert it for you) and related
syntax, which is all covered in the manual:
21.2.12.3 How to Get the Unique ID for the Last Inserted Row
<mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.2&filename=Getting_unique_ID>
If you insert a record into a table that contains an |AUTO_INCREMENT|
column, you can obtain the value stored into that column by calling
the |mysql_insert_id()| function.
You can check whether a value was stored into an |AUTO_INCREMENT|
column by executing the following code. This also checks whether the
query was an |INSERT| with an |AUTO_INCREMENT| index:
if (mysql_error(&mysql)[0] == 0 &&
mysql_num_fields(result) == 0 &&
mysql_insert_id(&mysql) != 0)
{
used_id = mysql_insert_id(&mysql);
}
For more information, see section 21.2.3.32 |mysql_insert_id()|
<mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.3&filename=manual_Clients.html>.
When a new |AUTO_INCREMENT| value has been generated, you can also
obtain it by executing a |SELECT LAST_INSERT_ID()| statement
|mysql_query()| and retrieving the value from the result set returned
by the statement.
That's straight out of the MySQL 5.0 manual. . .
Erik
Brandon Mercer wrote:
Barnett, Brian W. wrote:
What rdbms are you using?
Sorry, that would have been helpful huh! lol MySQL Connector/J
(obviously) 3.0.x. I think I know how to get the last id... but do I
create another insert the same way I did the first?
Thanks,
Brandon
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]