Re: MDB2 lastInsertID on postgres
| From: | Lukas Smith | Date: | Tue, 28 Mar 2006 09:22:19 +0000 |
| Subject: | Re: MDB2 lastInsertID on postgres | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23468@lists.php.net to get a copy of this message | ||
Paolo Sala wrote:
I'm trying to use lastInsertID method on pear::mdb2 in a postgreSQL 7.4.7 database but the method return an unknow error. This is an example code that generate the error:you can get additional information about the error using: $err->getUserinfo() The problem in your case is that since pgsql does not support autoincrement in the same way than mysql that you need to specify the optional $table and $field parameters to lastinsertid. you also need to make sure you have a sequence with the name "table_field_seq". The easiest way is to define the column as SERIAL: http://www.postgresql.org/docs/8.1/interactive/datatype.html#DATATYPE-SERIAL regards, Lukas$mdb2=& MDB2::factory($dsn); if ($mdb2->supports('transactions'))The result is:$mdb2->beginTransaction();$strSQL= 'INSERT INTO table (field) VALUES(\'field content\')'; $err=$mdb2->queryAll($strSQL); if (PEAR::isError($err))echo 'Query failed: '.$err->getMessage();$err=$mdb2->lastInsertID(); if (PEAR::isError($err))echo 'lastInsertID fails: '.$err->getMessage();if ($mdb2->in_transaction)$mdb2->rollback();lastInsertID fails: MDB2 Error: unknown errorThere is a way to know the last inserted id using mdb2 on a postgres database?