webForumDet fria alternativet

Fatal error: Call to a member function...?

10 svar · 605 visningar · startad av Guldstrand

GuldstrandMedlem sedan juli 20041 271 inlägg
#1

Jag får följande fel när jag testar ett script:

Fatal error: Call to a member function getarray() on a non-object

Koden är:

$sql = "select * from vote_wallpaper where cat_id='7' order by upload_date,upload_time desc limit 4";
		$result = $this->Conn->QueryRS($sql);
		$data = $result->getarray();		
		$this->Template->assignVal('eight_dim_img',$data);//print_r($data);

Vad betyder det, och hur löser jag det?

Peter SMedlem sedan dec. 20025 483 inlägg
#2

Det verkar som att $result är null eller EOF. Du får göra en sådan koll innan du försöker anropa getarray().

GuldstrandMedlem sedan juli 20041 271 inlägg
#3

Peter S skrev:

Det verkar som att $result är null eller EOF. Du får göra en sådan koll innan du försöker anropa getarray().

Ja, det kan stämma att det inte finns något resultat.
Men hur löser jag det? :r

Peter SMedlem sedan dec. 20025 483 inlägg
#4

Hur ser definitionen av QueryRS() ut? Vad returnerar den?

GuldstrandMedlem sedan juli 20041 271 inlägg
#5

Bra fråga. :r

Här är mer av koden:

		/********  Start : code for display of wallpapers/themes/rigntones etc in home page  *****************/

		//echo 
		$val=$_GET['val'];
		if ($val=='')$val=1;
		$sql = "select * from tblwallpaper order by rand() limit 6";
		$result = $this->Conn->QueryRS($sql);//echo "<br />";
		$data = $result->getarray();		
		$this->Template->assignVal('wall_paper',$data);//print_r($data);

		$sql = "select * from tbltheme order by rand() limit 6";
		$result = $this->Conn->QueryRS($sql);//echo "<br />";
		$data = $result->getarray();		
		$this->Template->assignVal('theme',$data);//print_r($data);
		
		$this->assignVal('val',$val);//print_r($data);
		echo "";
		
		$sql = "select * from vote_wallpaper where cat_id='7' order by upload_date,upload_time desc limit 4";
		$result = $this->Conn->QueryRS($sql);
		//FEL $data = $result->getarray(); 
		$this->Template->assignVal('eight_dim_img',$data);//print_r($data);
		
		$sql = "select * from vote_wallpaper where cat_id='5' order by upload_date,upload_time desc limit 4";
		$result = $this->Conn->QueryRS($sql);//echo "<br />";
		// FEL $data = $result->getarray();		
		$this->Template->assignVal('five_dim_img',$data);//print_r($data);
		
		
		$sql = "select * from vote_category";		
		$wall_cat = $this->Conn->QueryRS($sql);			
		$this->Template->assignVal('wall_cat',$wall_cat->getArray());
		
		$sql = "select *  from vote_users";
		$result = $this->Conn->QueryRS($sql);		
		$data = $result->getarray();		
		$this->Template->assignVal('most_rated_users',$data);
		$this->Template->assignVal('all_users',$data);
		
		/******** End :  code for wallpapers  ***************/
		//////////////
Peter SMedlem sedan dec. 20025 483 inlägg
#6

Var finns den här koden: $this->Conn->QueryRS definierad? Du verkar befinna dig i en klass så du måste visa mer kod. Inkluderar du några filer?

GuldstrandMedlem sedan juli 20041 271 inlägg
#7

Här är hela funktionen/klassen:

function Home()
    {
        $uid = $this->Session->getValue('userid');

        $this->Template->setTitle($this->U_TITLE."Home");
        $this->Template->setMeta("Keywords","mobile , mobile ringtone , mobile theme , mobile video");
        $this->Template->setMeta("Description","Free mobile tools like ringtone theme videos");
        $this->Template->renderTitleMeta();
				
        $uid=$this->Session->getValue('userid');

        $this->Template->assignVal('logged',$uid);
        $this->Template->smarty->register_block('trans1',array($this,'in_get_fri_num_all'),false);
        $this->getModuleHeader();
        
		//for left first dimension 
		$sql =sprintf(SQL_SEL_WALL);
		$result = $this->Conn->QueryRS($sql);
		$data = $result->getarray();
		
		$this->Template->assignVal('dimension',$data);
		
		$sql =sprintf(SQL_SEL_SET);
		$result = $this->Conn->QueryRS($sql);
		$data = $result->getarray();		
		$this->Template->assignVal('hand_set',$data);
		
		//$this->Template->assignVal('script_url',SCRIPT_URL);
		
        
        $sql=sprintf(SQL_RECENTTONE);
        $recenttone=$this->Conn->Query($sql);
        $this->assignVal('recenttone',$recenttone);
        
        $sql=sprintf(SQL_RECENTTHEME);
        $recenttheme=$this->Conn->Query($sql);
        $this->assignVal('recenttheme',$recenttheme);
        
        $sql=sprintf(SQL_RECENTVIDEO);
        $recentvideo=$this->Conn->Query($sql);
        $this->assignVal('recentvideo',$recentvideo);
		
		/********  Start : code for display of wallpapers/themes/rigntones etc in home page  *****************/

		//echo 
		$val=$_GET['val'];
		if ($val=='')$val=1;
		$sql = "select * from tblwallpaper order by rand() limit 6";
		$result = $this->Conn->QueryRS($sql);//echo "<br />";
		$data = $result->getarray();		
		$this->Template->assignVal('wall_paper',$data);//print_r($data);

		$sql = "select * from tbltheme order by rand() limit 6";
		$result = $this->Conn->QueryRS($sql);//echo "<br />";
		$data = $result->getarray();		
		$this->Template->assignVal('theme',$data);//print_r($data);
		
		$this->assignVal('val',$val);//print_r($data);
		echo "";
		
		$sql = "select * from vote_wallpaper where cat_id='7' order by upload_date,upload_time desc limit 4";
		$result = $this->Conn->QueryRS($sql);
		$data = $result->getarray(); 
		$this->Template->assignVal('eight_dim_img',$data); 
		
		$sql = "select * from vote_wallpaper where cat_id='5' order by upload_date,upload_time desc limit 4";
		$result = $this->Conn->QueryRS($sql);//echo "<br />";
		$data = $result->getarray();		
		$this->Template->assignVal('five_dim_img',$data);//print_r($data);
		
		
		$sql = "select * from vote_category";		
		$wall_cat = $this->Conn->QueryRS($sql);			
		$this->Template->assignVal('wall_cat',$wall_cat->getArray());
		
		$sql = "select *  from vote_users";
		$result = $this->Conn->QueryRS($sql);		
		$data = $result->getarray();		
		$this->Template->assignVal('most_rated_users',$data);
		$this->Template->assignVal('all_users',$data);
		
		/******** End :  code for wallpapers  ***************/
		//////////////
		
		$available_users = "";
		
		$sql="select * from vote_sessions";		
		$st = $this->Conn->QueryRS($sql);
		
		$i = 0;
		while (!$st->EOF) {
			$data = $st->fields['Data'];			
			
			$active_users = $this->get_sess_values($data);
			
			 foreach($active_users as $key=> $val){
				$userid_key = trim($key,'\"');
				$userid_val = trim($val,'\"');
				if($userid_key=="userid"){					
					$available_users[$i] = $userid_val;
				}
			 }
					
			$i++;
			$st->MoveNext();
		}
		
		//find users info
		//print_r($available_users);
		$str = "";
		if(!empty($available_users)){		
			for($j=0 ;$j < $i;$j++){
				$str .=$available_users[$j].",";					
			}
		}
		$str = rtrim($str,",");
		$sql = "select * from vote_users where ID in(".$str.")";
		//echo"<br />sql : $sql";
		$result = $this->Conn->Query($sql);
		$this->Template->assignVal('users_online',$result);		
	
		///////////////////////////////////chisty///////////////////////
		$u_data=$this->Conn->Query(SQL_USER_INFO);
		 $this->assignVal('u_data',$u_data);
		//print_r($u_data); exit;
		///////////////////////////////chisty//////////////////////////
		
		/*
		 $sql = "select * from vote_users where ID = '$uid' ";
        
        $rs_user = $this->Conn->QueryRS($sql);
        
        
        $this->Template->assignVal('upic',$rs_user->fields[pic]);
        $this->Template->assignVal('ucon',$rs_user->fields[Country]);
        $this->Template->assignVal('ugen',$rs_user->fields[gender]);*/
		//////////////////////////
      // echo $this->Settings->U
        $this->setTemplate('home');
        $this->getModuleFooter();
                
        $this->Render();
    }
Peter SMedlem sedan dec. 20025 483 inlägg
#8

Det måste finnas annan kod utanför Home() som definierar Conn, QueryRS() m.fl.

Men, den senaste koden du postade hjälpte ändå :)

 $sql = "select * from vote_wallpaper where cat_id='7' order by upload_date,upload_time desc limit 4";
        $result = $this->Conn->QueryRS($sql);
        if (!$result->EOF){
          $data = $result->getarray();        
          $this->Template->assignVal('eight_dim_img',$data);//print_r($data);
        }
GuldstrandMedlem sedan juli 20041 271 inlägg
#9

Peter S skrev:

Det måste finnas annan kod utanför Home() som definierar Conn, QueryRS() m.fl.

Men, den senaste koden du postade hjälpte ändå :)

 $sql = "select * from vote_wallpaper where cat_id='7' order by upload_date,upload_time desc limit 4";
        $result = $this->Conn->QueryRS($sql);
        if (!$result->EOF){
          $data = $result->getarray();        
          $this->Template->assignVal('eight_dim_img',$data);//print_r($data);
        }

Det hjälpte tyvärr inte. (Får samma fel.)

dbconnect

class dbConnect
{
        var $conn;

    // public variables
    var $LastErrorMessage = '';
    var $LastErrorNumber  = 0;
    var $Persistent       = 0;
    var $LastInsertID          = 0;
    var $LastAffectedRows = 0;

    // private variables
    var $_Server;
    var $_Username;
    var $_Password;
    var $_Database;
    var $_State = 0;
    var $_Engine;

function &dbConnect($server = null, $username = null, $password = null, $database = null, $persistent = 0)
{
        $this->_Engine = DB_DRIVER;
        $this->Persistant = $persistent;
                
    if (($server != null) && ($username != null) && ($database != null))
        {
                $this->open($server, $username, $password, $database);
    }
}

function open($server, $username, $password, $database)
{
    $this->_Server   = $server;
    $this->_Username = $username;
    $this->_Password = $password;
    $this->_Database = $database;
        $this->conn = &ADONewConnection($this->_Engine);
        if(DEBUG_MODE)
        {
                $this->conn->debug = true;                                
        }
        
    if ($this->Persistent == 1)
        {
                // open a persistent connection
                $this->conn->PConnect($this->_Server, $this->_Username, $this->_Password, $this->_Database);
    }
    else
        {
                // open a normal connection
                $this->conn->Connect($this->_Server, $this->_Username, $this->_Password, $this->_Database);
    }

    if ($this->conn)
        {
            $this->_State = 1;
            return true;
    }

    exit(sprintf(CU_ERR_DB_1000));
}
    
function close()
{
    if ($this->_State)
        {
        $this->conn->close();
        $this->_State = 0;
        return true;
    }
    return false;
}

function state()
{
    return $this->_State;
}
    
//This Function is needed to run only SQL commands that does not return anything
//ITS Like insert or update or delete command
function Execute($SQL)
{
        $this->QueryPrepare($SQL);
        
    if ($this->_State)
        {

        if ($this->conn->Execute($SQL)===false)
                {
            $this->LastErrorMessage = $this->conn->ErrorMsg();
            return false;
        }
        else 
        {
                if(stristr($SQL,"Insert ")!==false) $this->LastInsertID = $this->conn->Insert_ID();
                        $this->LastAffectedRows = $this->conn->Affected_Rows();                
                return true;
        }
    }
    return false;
}

//Its Execute a Simple Select Query which returns only 1 field or Value
function ExecuteSingle($strSQL)
{
        $this->QueryPrepare($strSQL);

    if ($this->_State)
        {
                $this->conn->SetFetchMode(ADODB_FETCH_NUM); 
        if ($result = $this->conn->execute($strSQL))
                {
            return $result->fields[0];
        }
        else
                {
            $this->LastErrorMessage = $this->conn->ErrorMsg();
        }
                $this->conn->SetFetchMode(ADODB_FETCH_ASSOC);         
    }
    return false;
}

//IF query returns only Single row of data then use this.
//If you need indexing from "0" use 0 as second parameter. 
//Default is "1" which returns Associative Array
function QuerySingle($strSQL, $associative = 1)
{
    switch ($associative)
    {   
        case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
        case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
    }

    $this->QueryPrepare($strSQL);

    if ($this->_State)
        {
        $result = $this->conn->GetRow($strSQL);

        if ($result)
                {
                        return $result;
        }
        else
                {
            $this->LastErrorMessage = $this->conn->ErrorMsg();                        
            return false;            
        }

    }
    return false;
}

function QuerySingleRS($strSQL, $associative = 1)
{
    switch ($associative)
    {   
        case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
        case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
    }

    $this->QueryPrepare($strSQL);

    if ($this->_State)
        {
        $result = $this->conn->Execute($strSQL);

        if ($result)
                {
                        return $result;
        }
        else
                {
            $this->LastErrorMessage = $this->conn->ErrorMsg();                        
            return false;            
        }

    }
    return false;
}

function QueryRS($strSQL, $associative = 1)
{
    switch ($associative)
    {   
        case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
        case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
    }
        
        $this->QueryPrepare($strSQL);

    if ($this->_State)
        {
        $result = $this->conn->Execute($strSQL);
        if ($result)
                {
                        return $result;
        }
        else
                {
            $this->LastErrorMessage = $this->conn->ErrorMsg();                        
            return false;
        }
    }
    return false;
}

//GET ALL THE TUPLES FOR A SELECT
function Query($strSQL, $associative = 1)
{
    switch ($associative)
    {   
        case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
        case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
    }
        
        $this->QueryPrepare($strSQL);

    if ($this->_State)
        {
        $result = $this->conn->GetAll($strSQL);
        if ($result)
                {
                        return $result;
        }
        else
                {
            $this->LastErrorMessage = $this->conn->ErrorMsg();                        
            return false;
        }
    }
    return false;
}

//Check Wheather Data Exists or Not in Table
//Works Fine For Single Row Check
function dataExists($SQL)
{
        $this->QueryPrepare($SQL);
        
    if ($this->_State)
        {
        $result = $this->QuerySingle($SQL);
        if (is_array($result))
                {
            unset($result);
            return true;
        }
    }

    return false;
}

//GET HOW MANY ROWS IN A RECORDSET
function numRows($recordSet)
{
        if ($this->_State) {
                $result = count($recordSet);
                return $result;
        }
}

//GET THE RECENT INSERT ID
function getInsertID()
{
        return $this->LastInsertID;
}

//GET AFFECTED ROWS
function getAffectedRows()
{
        return $this->LastAffectedRows;
}

//TRY TO UPDATE A RECORD, IF NOT FOUND THEN INSERT
function insertOrUpdate($table, $arrFields, $keyCols,$autoQuote=false)
{
        $table = str_replace("tbl", ' '.DB_PREFIX, $table);
        $ret = $this->conn->Replace($table, $arrFields, $keyCols, $autoQuote);
        return $ret; 
}

function Prepare($string)
{
        if (!get_magic_quotes_gpc())
        {
                $string = addslashes($string);
        }
        return trim($string);
}

function QueryPrepare(&$string)
{
        $string = str_replace(" tbl", ' '.DB_PREFIX, $string);
        $string = str_replace(",tbl", ','.DB_PREFIX, $string);
    $string = $this->Prepare($string);
}

}
Peter SMedlem sedan dec. 20025 483 inlägg
#10

Är det på samma rad du får felet?

GuldstrandMedlem sedan juli 20041 271 inlägg
#11

Peter S skrev:

Är det på samma rad du får felet?

Ja!

143 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
141 ms — hämta tråd, inlägg och bilagor (db)