Avatar billede holmqvist Nybegynder
28. februar 2005 - 11:41 Der er 5 kommentarer og
1 løsning

auto index

I've asked this before and got an answer on what to use to get the last inserted auto index, so I wrote an SQL-query like this:

SELECT ID FROM personuppgifter
WHERE ID=LAST_INSERT_ID();

(ID is my column name where I use auto_increment)
but it doesn't seem to work, can anyone tell what's wrong or how I should use the "LAST_INSERT_ID()" function..
Avatar billede arne_v Ekspert
28. februar 2005 - 11:47 #1
If the INSERT statement and this SELECT statement are executed with the
same connection, then it should work.
Avatar billede arne_v Ekspert
28. februar 2005 - 11:48 #2
BTW if you only need the ID then:

SELECT LAST_INSERT_ID()

is enough.
Avatar billede holmqvist Nybegynder
28. februar 2005 - 11:58 #3
With the same connection doesn't mean, the same SQL-query does it? It should work if I place the queries after eachother..
and
SELECT LAST_INSERT_ID() Should get the same answer as my long query?

the reason it didn't work for me was that I tried the SQL-query in the database then, not within the same connection.. I'm gonna try it in the PHP-document now then.
Avatar billede arne_v Ekspert
28. februar 2005 - 12:05 #4
It means connection as in the return value from mysql_connect
Avatar billede holmqvist Nybegynder
28. februar 2005 - 14:09 #5
Ok, now I've finally got it working the way I wanted it.. :)
Svar?
Avatar billede arne_v Ekspert
28. februar 2005 - 14:10 #6
jep
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester