jon_tries_php Posted September 4, 2008 Share Posted September 4, 2008 I am completely new to PHP and am attempting to make moodle work with Firebird. I'm not getting very far. Anyway, I need to return the primary key from an insert statement. the code goes something like this $sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)"; $this->writes++; // what does this do? if (!$rs = $this->adodb->Execute($sql, $params)) { $this->report_error($sql, $params); return false; } this works fine, except I need to know what is the generated primary key, so I tried the this $sql = 'SELECT max(id) from '.$this->prefix.$table; if (!$rs1 = $this->adodb->Execute($sql)) { $this->report_error($sql); } error_log('JLJ fieldcount '.$rs1->FieldCount) ; error_log('JLJ fieldvalue '.$rs1->fields[0]) ; My problem is FieldCount and fields[0] is showing up as blank. I assume the query executed as rs1 is assigned. Is my query returning nothing because the insert is not committed? Is there another way to retrieve the generated primary key? Am I doing this completely wrong? Any pointers or help would be greatly appreciated. Jon Link to comment https://forums.phpfreaks.com/topic/122691-need-help-working-with-adodb/ Share on other sites More sharing options...
aschk Posted September 4, 2008 Share Posted September 4, 2008 You're assuming that Execute($sql) is returning an array of information. What ADODB library are you working with because the object syntax you're working with is unfamiliar. After the Execute() call I would expect to see something along the lines of: $row = $this->adodb->fetch(); // This should fetch the first row of your resultset. where $row will be the associative array of information you're after. Link to comment https://forums.phpfreaks.com/topic/122691-need-help-working-with-adodb/#findComment-633578 Share on other sites More sharing options...
jon_tries_php Posted September 4, 2008 Author Share Posted September 4, 2008 based on the adodb.inc.php its @version V5.04a 25 Mar 2008 when I tried fetch I got this Call to undefined method ADODB_firebird::Fetch() I tried this instead if (!$rs1->_fetch()) { error_log('Fetch failed '); } return (int)$rs1->fields[0]; which again was not returning a value. Adodb-ibase.inc.php._fetch had the following code if ($this->fetchMode == ADODB_FETCH_ASSOC) { $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE); } The call to GetRowAssoc would cause the field to lose its value. Seeing as these are fairly low level functions I would assume that I should not be tweaking this things. However commenting out the GetRowAssoc call allowed me to access the field values. Does anyone know what is going on here? Link to comment https://forums.phpfreaks.com/topic/122691-need-help-working-with-adodb/#findComment-633759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.