---
title: "Fatal error: Call to a member function...?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/176682-fatal-error-call-to-a-member-function"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Guldstrand"
published: "2009-02-02T20:09:05.000Z"
updated: "2009-02-02T21:19:01.000Z"
replies: 10
views: 608
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/176682-fatal-error-call-to-a-member-function"
---

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

## #1 — Guldstrand, 2009-02-02T20:09Z

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

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

Koden är:

```php
$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?

Permalänk: https://www.webforum.nu/p/176682

## #2 — Peter S, 2009-02-02T20:12Z

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().

Permalänk: https://www.webforum.nu/p/2167474

## #3 — Guldstrand, 2009-02-02T20:19Z

> **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

Permalänk: https://www.webforum.nu/p/2167478

## #4 — Peter S, 2009-02-02T20:21Z

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

Permalänk: https://www.webforum.nu/p/2167479

## #5 — Guldstrand, 2009-02-02T20:28Z

Bra fråga.   :r 

Här är mer av koden:

```php
		/********  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  ***************/
		//////////////
```

Permalänk: https://www.webforum.nu/p/2167480

## #6 — Peter S, 2009-02-02T20:31Z

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?

Permalänk: https://www.webforum.nu/p/2167481

## #7 — Guldstrand, 2009-02-02T20:40Z

Här är hela funktionen/klassen:
    

```php
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();
    }
```

Permalänk: https://www.webforum.nu/p/2167483

## #8 — Peter S, 2009-02-02T20:43Z

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

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

```php
 $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);
        }
```

Permalänk: https://www.webforum.nu/p/2167484

## #9 — Guldstrand, 2009-02-02T21:04Z

> **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å :)
>
>
> ```php
>  $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

```php
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);
}

}
```

Permalänk: https://www.webforum.nu/p/2167546

## #10 — Peter S, 2009-02-02T21:12Z

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

Permalänk: https://www.webforum.nu/p/2167550

## #11 — Guldstrand, 2009-02-02T21:19Z

> **Peter S skrev:**
>
> Är det på samma rad du får felet?

Ja!

Permalänk: https://www.webforum.nu/p/2167551

---

Tråden på webben: https://www.webforum.nu/amne/php/176682-fatal-error-call-to-a-member-function
