#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Apr 5, 2010 14:03:19 GMT -8
Whenever I use MySQL databases for anything PHP related, I set a primary key column with the name `id` and auto-increment on each table as a way of accessing everything easily.
My problem comes if I want to know what the auto-increment ID is when I run the insert command. Is there a way other than polling the table and guessing the next number to get what ID an insert command was assigned, without running a SELECT command on another column to find the last row just inserted?
|
|
inherit
77753
0
Jul 18, 2024 12:23:50 GMT -8
Bob
2,623
April 2006
bobbyhensley
|
Post by Bob on Apr 5, 2010 22:17:57 GMT -8
Whenever I use MySQL databases for anything PHP related, I set a primary key column with the name `id` and auto-increment on each table as a way of accessing everything easily. My problem comes if I want to know what the auto-increment ID is when I run the insert command. Is there a way other than polling the table and guessing the next number to get what ID an insert command was assigned, without running a SELECT command on another column to find the last row just inserted? Use the mysql_insert_id () function.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Apr 6, 2010 19:06:23 GMT -8
Very useful function. Does it work if you INSERT'd in a previous session, or can it only be used on the same page as the INSERT statement?
|
|
inherit
16846
0
Nov 19, 2012 15:20:20 GMT -8
Chris
3,036
December 2003
cddude
|
Post by Chris on Apr 11, 2010 22:52:00 GMT -8
Very useful function. Does it work if you INSERT'd in a previous session, or can it only be used on the same page as the INSERT statement? To my knowledge, same session only. For others, you can just use something like SELECT `id` FROM `table` ORDER BY `id` DESC LIMIT 1 (My syntax is rusty, so I apologize if that's wrong.)
|
|