Yes, using the PHP functions for MySQL, it works. But I am using the abstraction class ADODB to make the queries in my database. Why? Probably we will change the database system (probably to PostgreSQL) and we don want to change all the code to make the things work in the new BD. I don't know if anyone have ever used this class before. I am trying to use the GenID method, because in PostgreSQL we don't have the auto_increment field type. I made it work (with the Insert_ID method), but it isn't portable. Does anyone that knows this class can help me? Thanks a lot for the replies. -- Renne Rocha rennerocha@xxxxxxxxx 55 11 8467-9456 On 7/19/06, John Meyer <john.l.meyer@xxxxxxxxx> wrote:
Wouldn't this: $id = mysql_insert_id(); $query = "UPDATE tablename SET id=" . ($id + 1); $result = mysql_query($query); Be a little simpler. But like I said, I'm confused over the need for this in the first place, seeing as how an "auto_incremented" primary key is self-descriptive. or are you saving this somewhere else in the DB? On 7/19/06, chris smith <dmagick@xxxxxxxxx> wrote: > On 7/19/06, Renne Rocha <rennerocha@xxxxxxxxx> wrote: > Hello, > > I am using the ADODB class to connect to a MySQL server. I am trying > to generate an ID with the method GenID(), but when I tried this: > > $id = $db->GenID('table'); > > The value of $id is equal to zero. I know that MySQL doesn't use > sequences like PostgreSQL does (I've used this code in a PostgreSQL > project), but in the documentation of ADODB I saw that it is possible > to use it. Is there any trick about how to make it work? You'll need to insert a value into the table first, then you can do: $query = "UPDATE tablename SET id=LAST_INSERT_ID(id+1)"; $result = mysql_query($query); $id = mysql_insert_id(); This is in the mysql docs somewhere...
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php