[SOLVED] Issue with RecordCount?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
markS
Forum Members
Forum Members
Posts: 58
Joined: Wed Aug 20, 2008 3:04 pm

[SOLVED] Issue with RecordCount?

Post 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.
vilkis

Re: Issue with RecordCount?

Post 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
markS
Forum Members
Forum Members
Posts: 58
Joined: Wed Aug 20, 2008 3:04 pm

Re: [SOLVED] Issue with RecordCount?

Post 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.
Post Reply

Return to “Developers Discussion”