Do I do it right

First I insert the new INSERT INTO table data into the INSERT INTO table

And then to get the id value of the last value inserted I use

 SELECT LAST_INSERT_ID() FROM `table` LIMIT 0 , 1; 

is the limit needed here or not and what does the query return without a limit at all?

I forgot everything, remind someone who knows

  • 3
    First tip: forget about mysql_ * functions, use PDO. Second: mysql_insert_id () - will return the latest ID-code. Third (on the case): LIMIT is not required, as a result, in no case will there be more than 1 record, but! dev.mysql.com/doc/refman/5.1/en/… , if there is a construction like INSERT INTO table (name) VALUES ('Michael'), ('John'), ('Peter'); where id is AUTO_INCREMENT, then you will get the record ID with name = Michael, i.e. first auto-increment ID-shki. id john and Peter records are lost - dekameron

1 answer 1

The limit is not needed, it will simply return the last id, like even FROM No need to specify. if in php, then there is just a function mysql_insert_id() - Get the ID generated in the last query