Jump to content

need help working with ADODB


jon_tries_php

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.