How to call mysql_insert_id
A long time ago, I posted this query: If I use the auto-increment feature for a couple of normallized relations, how do I insert into them? Specifically, when I insert into a relation with the autoincrement feature on the primary key, how do I get the value of the index on the newly created row so I can use that the value of a foreign key in another relation? That's database specific, and you haven't specified a database. * In MySQL - mysql_insert_id() How do I call this function? I was hoping I could use SQL such as SELECT mysql_insert_id() FROM XYZ but I discovered that does not work. I'm using a mixture of java and perl. I see in my old documentation that PHP programmers can call such a function. Thanks, Siegfried
Re: How to call mysql_insert_id
On Apr 11, 2005 10:50 PM, Siegfried Heintze [EMAIL PROTECTED] wrote: * In MySQL - mysql_insert_id() How do I call this function? I was hoping I could use SQL such as SELECT mysql_insert_id() FROM XYZ but I discovered that does not work. I'm using a mixture of java and perl. I see in my old documentation that PHP programmers can call such a function. SELECT LAST_INSERT_ID(); HTH, JP -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: How to call mysql_insert_id
Thanks, JP. And will this work for multi-threaded, multi-user applications? Siegfried -Original Message- From: Jan Pieter Kunst [mailto:[EMAIL PROTECTED] Sent: Monday, April 11, 2005 3:05 PM To: mysql@lists.mysql.com Subject: Re: How to call mysql_insert_id On Apr 11, 2005 10:50 PM, Siegfried Heintze [EMAIL PROTECTED] wrote: * In MySQL - mysql_insert_id() How do I call this function? I was hoping I could use SQL such as SELECT mysql_insert_id() FROM XYZ but I discovered that does not work. I'm using a mixture of java and perl. I see in my old documentation that PHP programmers can call such a function. SELECT LAST_INSERT_ID(); HTH, JP -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: How to call mysql_insert_id
On Apr 12, 2005 1:37 AM, Siegfried Heintze [EMAIL PROTECTED] wrote: Thanks, JP. And will this work for multi-threaded, multi-user applications? Siegfried Yes: The last ID that was generated is maintained in the server on a per-connection basis. This means the value the function returns to a given client is the most recent AUTO_INCREMENT value generated by that client. The value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that you can retrieve your own ID without concern for the activity of other clients, and without the need for locks or transactions. See http://dev.mysql.com/doc/mysql/en/information-functions.html and look for LAST_INSERT_ID(). JP -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
How To call mysql_insert_id
Hi, I am a newbie in MySQL. I use an auto_increment to insert to one of the column. How do I get the value inserted? The documentation seems to suggest using mysql_insert_id() function. But when I tried to call it using Select mysql_insert_id() or Select mysql_insert_id() from TABLE_NAME gives me error. I tried to find something in the doc, but it does not really help. Please help. Thanks in advance. Reuben D. Budiardja - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: How To call mysql_insert_id
You were close to it. But he way to get the last inserted item on AUTO_INCREMENT field is for example: id = mysql_insert_id(mysql); printf(The last insert is: %d\n, id); And mysql is what was return to you when you open your connection to the database. Daniel Hi, I am a newbie in MySQL. I use an auto_increment to insert to one of the column. How do I get the value inserted? The documentation seems to suggest using mysql_insert_id() function. But when I tried to call it using Select mysql_insert_id() or Select mysql_insert_id() from TABLE_NAME gives me error. I tried to find something in the doc, but it does not really help. Please help. Thanks in advance. Reuben D. Budiardja - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: How To call mysql_insert_id
At 6:45 PM -0500 9/30/01, Reuben D Budiardja wrote: Hi, I am a newbie in MySQL. I use an auto_increment to insert to one of the column. How do I get the value inserted? The documentation seems to suggest using mysql_insert_id() function. But when I tried to call it using Select mysql_insert_id() or Select mysql_insert_id() from TABLE_NAME mysql_insert_id() is the C API function for obtaining that value. Use LAST_INSERT_ID() instead: SELECT LAST_INSERT_ID() You don't want SELECT LAST_INSERT_ID() from TABLE_NAME, probably. That will give you the insert-id value once for each row in TABLE_NAME. gives me error. I tried to find something in the doc, but it does not really help. http://www.mysql.com/doc/M/i/Miscellaneous_functions.html Please help. Thanks in advance. Reuben D. Budiardja -- Paul DuBois, [EMAIL PROTECTED] - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php