Marc Serra wrote:
Hi,
i use PEAR DB with a mysql database and i want to know if there is a
solution to get last inserted id in a table.
I see that I can use sequences but it doesn't work with mysql.
Thanks,
Marc.
Check this out:
http://pear.php.net/manual/en/package.database.db.intro-
[straying OT, but...]
> Instead of incrementing to find the next row to count them, you dont have to
> set the ID if it is auto increment. MySQL will do it for you (and i think it
> might fill the holes too). Also, to get the num. of rows just do this -
>
> $get_rows = mysql_query("SELECT * FROM `
If you have an auto_increment mysql field, it's supposed to save you
the time of computing the "next" ID. the database will handle it for you.
Use "0" as the ID for new rows and mysql will automagically compute
the next ID.
All of this info is on the mysql.com/doc/ site... please check there
in
Instead of incrementing to find the next row to count them, you dont have to
set the ID if it is auto increment. MySQL will do it for you (and i think it
might fill the holes too). Also, to get the num. of rows just do this -
$get_rows = mysql_query("SELECT * FROM `table`");
$num_rows = mysql_num
> my primary key column ("id") is set to auto_increment as usual which is
very
> handy. But when I delete a row, the auto_increment just keeps incrementing
> and there's this 'hole' left where I deleted the row!
This is the way it should be, and it's like that for a reason - if you have
other tab
5 matches
Mail list logo