Page 1 of 1

[SOLVED] Issue with RecordCount?

Posted: Wed Apr 25, 2012 10:18 am
by markS
Hello,

I'm working on a module and I'm having trouble with getting the RecordCount from adodblite with the most recent cms 1.10.3 to give me any answer at all.

The code is very simple and is working on an older installation, here's a snippet of the function:

Code: Select all

    
function _listTypes() {
        //provide list of type objects as an array        
        //$gCms = cmsms();
        $db = cmsms()->GetDb(); 
        //$db = $gCms->GetDb();
  
        //run the query
        $query = "SELECT typ.* FROM ".cms_db_prefix()."module_msx_types AS typ ORDER BY typ.xTypeOrder ASC, type.xTypeName ASC";
        $dbresult = $db->Execute($query);
        $this->typeCount = $dbresult->RecordCount();
        
         //blah....
}
This is admin side, and the code always bails at the $dbresult->RecordCount() call with "PHP Fatal error: Call to a member function RecordCount() on a non-object in..."

I've tried a few methods of initialising the db, all with the same results. Is this a bug or am I being stupid? Personally, I know what my money's on! :)

Thanks in advance if anyone can show me where I'm going wrong.

Regards,
Mark.

Re: Issue with RecordCount?

Posted: Wed Apr 25, 2012 10:32 am
by vilkis
It means that $db->Execute($query) does not return object...

Did you try

Code: Select all

$dbresult = $db->Execute($query); var_dump($dbresult,$db->ErrorMsg());
vilkis

Re: [SOLVED] Issue with RecordCount?

Posted: Wed Apr 25, 2012 10:38 am
by markS
Hello,

Yes, stupidity is the answer! :)

I'll post the explanation because this really confused me for quite a while, right up until I posted the query online. Oh well...

I was getting the error "Call to a member function RecordCount() on a non-object" because my query was invalid. I'd made a typo in the query and obviously there was no $dbresult so there could not be a RecordCount. I'm now reworking my query to check for a valid $dbresult before asking for a count...

Sorry for the noise.

Mark.