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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy of auto_increment column

Status
Not open for further replies.

jggretton

Programmer
May 11, 2006
4
GB
Hello, i've got an `id` column which auto_increments, but I also would like another column initially set to the same number as `id`.

Is this a sensible way of doing this on mySQL 4.0.26:

"INSERT INTO `bla` ( `id` , `id2`, `text`) VALUES ('', '', 'Bob'); UPDATE `bla` SET `id2`=LAST_INSERT_ID( ) WHERE id=LAST_INSERT_ID( );"

And send it as one query from php?

Thank you for any help you can give me,

James
 
I don't know if PHP allows SQL statements to be strung together like that. But whether it does or not, those statements would seem to be fine.
 
I believe in PHP you would still have to send it as two separate queries. You won't have to worry about the value of the insert id changing though since it is independant of other users inserting rows. I believe in PHP though you use mysql_insert_id() rather than last_insert_id().
 
Fantastic, very pleased i don't have to worry about the insert id changing. Thanks to both of you for your help!

James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top