Re: DB_DataObject - how to insert a value for an autoincrement primary key field
| From: | Ian Warner | Date: | Thu, 15 Feb 2007 11:48:22 +0000 |
| Subject: | Re: DB_DataObject - how to insert a value for an autoincrement primary key field | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26588@lists.php.net to get a copy of this message | ||
I would simply switch off the auto increment, and always insert the ID then.
When you want to make an insert without the ID present then simply get the last insert ID and add 1
Basically what you want to do goes against the auto increment policy.
cheers
Ian
Yashesh Bhatia wrote:
Hi, I'm using DB_DataObject 1.8.5 and have created DAO for my tables. One of the tables employee has a field id which is of type unsigned int and is defined as the primary key - autoincrement. When i try to insert an employee record into the table, sometimes i need to use the system generated value for id and sometimes a user defined value. when using system generated value the insert works fine $dao = new DAO_Employee(); $dao->name = "foobar"; $dao->insert(); however if i try to have a user defined id the insert does not use the value of 'id' as set in the DAO but instead generates a new one and assigns it to dao. $dao = new DAO_Employee(); $dao->id = 11231; $dao->name = "baz"; $dao->insert(); The above insert does not use id value 11231 but instead uses the next value of autoincrement. Is there anyway one can enforce the insert method to use the id value set in the dao rather than the next auto increment value ? Thanks. Yashesh Bhatia ---------------------------------------------------------------- Go Pre http://www2.localaccess.com/rlalonde/pre.htm ----------------------------------------------------------------
Attachment: [application/x-pkcs7-signature] S/MIME Cryptographic Signature smime.p7s