Re: DB_Object->insert() not returning ID
| From: | Alan Knowles | Date: | Tue, 30 Nov 2004 06:33:53 +0000 |
| Subject: | Re: DB_Object->insert() not returning ID | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15916@lists.php.net to get a copy of this message | ||
Ken Restivo wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, Nov 15, 2004 at 10:46:12AM -0800, Justin Patrin wrote:$do->insert() should always return last_insert_id(), unless the schema data is wrong (eg. not uptodate or something) Otherwise you have found a bug..On Sun, 14 Nov 2004 21:23:06 -0800, Ken Restivo <ken@restivo.org> wrote:On Sun, Nov 14, 2004 at 07:36:41PM -0800, Ken Restivo wrote:One more: inserts succeed but always return 1 as an ID. I supposed I can hack around this with a raw query for last_insert_id(), but the docs say insert() should return this.
Wow - those are really old notes :) should be fixed in CVS.Looking at the DB_DataObject code, insert() says it returns true, false, or 0. Looks like the online docs are wrong. Look at the online API docs.
Thanks. The API docs also have the wrong information in the main body (about returning the last inserted ID), but with a note that says "mysql-specific? fixme". My fault for missing that, I guess. It does describe the return value correctly. I read somewhere that the inserted ID gets inserted into the object after the ->insert().Is that a reliable, safe way to get the last inserted ID? This is needed so you can run update on the object. - It's not a bad place to get the data from..
I think what I'm saying is, I can't believe that I have to write a utility function Nor can I :)Regards Alan
- -ken - -- - --------------- The world's most affordable web hosting. http://www.nearlyfreespeech.net -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQFBq65ze8HF+6xeOIcRAkCIAJwPbHMjYXg7CpncXhMJST48VsrWywCfYCyc oqlBnT2UNdGrPBk9n7AbILs= =GgM5 -----END PGP SIGNATURE-----