FormBuilder: Accessing Last Insert ID question / suggestion
| From: | Sarah Gray | Date: | Fri, 01 Apr 2005 17:27:48 +0000 |
| Subject: | FormBuilder: Accessing Last Insert ID question / suggestion | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-18476@lists.php.net to get a copy of this message | ||
List,
I may be missing something and if so please correct me, but I do not
see an easy way to get the last insert id when using FormBuilder.
Assuming that you are using auto_incrementing primary keys, of course.
For instance, using DB_DataObject you can get the id of your last insert
like this:
$person = new DataObjects_Person;
$person->name='fred';
$id = $person->insert();
But using the FormBuilder insert syntax,
$form->process(array(&$fg,'processForm'), false );
you cannot easily access the last insert -- this statement returns 1
(for success), not the id.
However, in FormBuilder on line 2319, the insert code reads:
switch ($action) {
case DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT:
$id = $this->_do->insert();
$this->debug('ID ('.$pk.') of the new object:
'.$id.'<br/>');
break;
etc...
Would it be possible to make $id a property of the fb object? So for
instance the code could instead read:
switch ($action) {
case DB_DATAOBJECT_FORMBUILDER_QUERY_FORCEINSERT:
$this->last_insert_id = $this->_do->insert();
$this->debug('ID ('.$pk.') of the new object: '.
$this->last_insert_id.'<br/>');
break;
etc
and have
var $last_insert_id; be one of the object properties?
Then, after the insert you could easily access $fb->last_insert_id in
your scripts?
***
If already possible and I'm missing it, let me know. Otherwise, would
this make sense as an addition?
Thanks,
Sarah