Friday 29 December 2017

how to select last autoincrement id using php and mysql













I
have an inset command such
as



insert (name)
values($name);


I have
id column as autoincrement. How can I get the id of the inserted record
after inserting.


class="post-text" itemprop="text">
class="normal">Answer




insert (name)
values($name);

SET @lastid = LAST_INSERT_ID();
select
blah_blah from table where id =
@lastid;


To get that
back into php, you do a normal mysql select on it like
this:



select
@lastid;

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...