Re: Class ADODB - Method GenID() in MySQL
| From: | chris smith | Date: | Wed, 19 Jul 2006 14:25:34 +0000 |
| Subject: | Re: Class ADODB - Method GenID() in MySQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-239573@lists.php.net to get a copy of this message | ||
On 7/19/06, Renne Rocha <rennerocha@gmail.com> 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... -- Postgresql & php tutorials http://www.designmagick.com/