Re: auto_increment and INSERT INTO

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

 



On Sun, 22 Jan 2006 15:08, Ron Piggott (PHP) wrote:
> I have various tables where a column is set to auto_increment in my
> table structure.  I have been using the following INSERT query format:
>
> INSERT INTO table VALUES ('$auto_increment_variable','$variable_1',
> '$variable_2')
>
> and then in applications where I have needed to know the value of the
> $auto_increment_variable I have immediately queried the table for
> $variable_1 and $variable_2 and used
>
> $reference = mysql_result($result,$i,"reference");
>
> to determine what numeric value was assigned.
>
> Is there a way I may find out what value was assigned to the
> $auto_increment_variable when the INSERT INTO query is issued?

Yes. Again, it's in the PHP docs if you look in http://www.php.net/mysql 
for "Get the ID generated from the previous INSERT operation"

Really, you should try the docs first instead of falling back on the soft 
option of asking the list.

Also, just as a side note, you don't need to provide a value for the 
auto-increment field; that's why it is called auto as it does the 
incrementing automatically. If your response to that is "I need the 
values in a specific order" then you have the wrong idea of what the 
auto-increment field is for.



Cheers
-- 
David Robley

Set laser printers to "stun".

-- 
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