DB_DataObject->insert() ... Not returning inserted row ID.

From: Date: Fri, 07 Oct 2005 10:02:22 +0000
Subject: DB_DataObject->insert() ... Not returning inserted row ID.
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21270@lists.php.net to get a copy of this message
Scratch that.. It¹s working fine.. For some reason it wouldn¹t echo out correctly with this: die($id); ..but this seems to work: die(Œkey¹.$id); bizzarre! 8-? N. ------ Hi there, I¹m having trouble with the insert() method not returning the row ID of the record inserted. This is on MySQL 4.x, PHP4.3.9 on Mac OS X 10.4.2, and Apach 2.0.52 What seems strange is that Œusenative¹ is being set to Œ1¹, which means (as far as I can tell) that DB_DataObjects knows that the table is auto-increment on mysql, and should therefore use the mysql_next_id() function to return the inserted row id. Here is the sequence array, primary key and $usenative being echoed out: Array ( [0] => article_id [1] => 1 [2] => ) key: article_id usenative: 1 DataObject.php 1.7.15 contains this code on about line 900: <code> if (($key !== false) && !$useNative) { if (!$seq) { $this->$key = $DB->nextId($this->__table); } else { $f = $DB->getOption('seqname_format'); $DB->setOption('seqname_format','%s'); $this->$key = $DB->nextId($seq); $DB->setOption('seqname_format',$f); } } </code> For MySQL, this is where the $key (which is the value returned by insert() ) is set. However, if $useNative is set, this entire if statement is skipped and $key is not set. This doesn¹t make sense, as (by my understanding) $useNative is set when the table is auto-increment. Is this a bug? Thanks, Noel -- Noel da Costa Managing Director Arc Contracting Limited www.arc2.co.uk +44 (0)78 7942 7940

« previous php.pear.general (#21270) next »