Re: DB_Object->insert() not returning ID
| From: | Ken Restivo | Date: | Mon, 15 Nov 2004 05:23:06 +0000 |
| Subject: | Re: DB_Object->insert() not returning ID | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15500@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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.
>
OK well I did this, but I'm still kind of suspicious about why I had to:
function lastInsertID($obj)
{
$db =& $obj->getDatabaseConnection();
$data =& $db->getOne('select last_insert_id()');
if (DB::isError($data)) {
die($data->getMessage());
}
return $data;
}
- -ken
- --
- ---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBmD06e8HF+6xeOIcRAmN0AJ95O5mjbxWDsJji9TFty0VoOxkmxwCfYVfJ
mBNYHTiT7LGWmMv7EbbNIa4=
=QDmA
-----END PGP SIGNATURE-----