[PEAR] How to get the value of an auto_increment primary key after an insert ?

[PEAR] How to get the value of an auto_increment primary key after an insert ?

am 09.09.2006 14:52:17 von reply

In a mysql database you have a table, with an integer as primary key. You've
specified auto_increment.
Using PEAR to access your database how do you get hold of the value of the
primary key of a row you just inserted ?
The PEAR manual mentions sequences, but that is something outside of the
table you are using. As I read it, you cannot specify step and startnumber
using PEAR. But you can when you create the sequence in mysql with a create
sequence statement.
If I would use this, I guess I would have to remove the auto_increment
specification on the primary key.
So I have a workable solution, but still would like to know if there isn't
an alternative to get hold of the number of a primary key after an insert
using PEAR.

thanx,

Pugi!

Re: How to get the value of an auto_increment primary key after an insert ?

am 11.09.2006 17:01:34 von nc

Pugi! wrote:
>
> In a mysql database you have a table, with an integer
> as primary key. You've specified auto_increment.
> Using PEAR to access your database how do you
> get hold of the value of the primary key of a row you
> just inserted ?

Call mysql_insert_id():

http://www.php.net/mysql_insert_id

Cheers,
NC

Re: How to get the value of an auto_increment primary key after an insert ?

am 11.09.2006 20:43:23 von unknown

Post removed (X-No-Archive: yes)