DB query in UDT? [solved]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
pumuklee

DB query in UDT? [solved]

Post by pumuklee »

hi
i create a user defined tag "contor"

Code: Select all

$dirname = dirname(__FILE__);
$filename = $dirname."/contor/contornr.php";
require_once($filename);

echo(contornr(session_id());
and the contornr.php contains something like this

Code: Select all

function contornr($sid)
{
	$locsid = $sid;//sessionid
	$ip = GetIP();//client ip
	
	global $gCms;
	global $db;
	$db =& $gCms->GetDb();
	 
	if($db)
	{
		//select rows which sessionid is = new sessionid
		$operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
		$execres = $db->Execute($operation); 
		
		if($execres->RowCount() == 0)//if not exist the new sessionid,insert new row
		{
		...
		}
		elseif($execres->RecordCount() > 0)//if exist the new sessionid, modify the old one
		{
			$rcounter = 0;			
			while($row = $execres->FetchRow())
			{
                          ...
			}
		}
                ...
		return $contor;
	}			
	else 
		return "";			
}
the problem is that my RecordCount and FetchRow function said that "call to a member function on a non-object"

so that here $result = $db->Execute($operation);
$result - is not an object

what i missed?
i think i must something to include in my file

thanks
Last edited by pumuklee on Fri Jan 26, 2007 9:14 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: DB query in UDT?

Post by calguy1000 »

You should check the result of the Execute statement to make sure it is not false:

Code: Select all

$db =& $gCms->GetDb();
$query = "SELECT * FROM ".cms_db_prefix()."table_name";
$dbresult = $db->Execute( $query );
if( !$dbresult ) 
  {
     echo $db->ErrorMsg();
  }
Also

Don't use RowCount, use RecordCount in your code.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
pumuklee

Re: DB query in UDT?

Post by pumuklee »

hi
yes you has right
this was the problem
the query was not executed because an error
and the error message was "call to a member function on a non-object" for FetchRow

thanks
Locked

Return to “Modules/Add-Ons”