Help - Search - Members - Calendar
Full Version: MySQL auto-increment
HTMLHelp Forums > Programming > Databases
CodeKing
If I create a column with auto-increment in mySQL, can I have the number it generates be returned to me via PHP?
Brian Chandler
I think it is. Have you looked in the php manual?
mike007
QUOTE(CodeKing @ Jan 30 2008, 06:24 PM) *

If I create a column with auto-increment in mySQL, can I have the number it generates be returned to me via PHP?


If you set a colum on auto-incement it will generate a unique number in that cell. It will allways be the highest number possible in the table. So if you want it back in php, just select the row with the highest number in the auto-incement cell and you have you latest input.

greets

W.pothof
http://www.finishedwebsites.nl
Darin McGrew
QUOTE
If you set a colum on auto-incement it will generate a unique number in that cell. It will allways be the highest number possible in the table. So if you want it back in php, just select the row with the highest number in the auto-incement cell and you have you latest input.
Watch out for race conditions. If a second process creates another row, then the one you created won't be the one with the highest number any longer.
Brian Chandler
I suppose I'll try again. Have you looked in the php manual? Particularly

http://jp2.php.net/manual/en/function.mysql-insert-id.php

(Obviously, as Darin suggests, it's no good doing a separate operation, which isn't guaranteed to be the right answer.)

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.