Jump to content

Fatal Error Call To A Member Function Prepare() On A Non-Object


mostafatalebi

Recommended Posts

fatal error Call to a member function prepare() on a non-object

I get this error. I don't know how to solve it?

I instance it from this code:

<?php
           $something = new login_table("localhost", "root", "", "object");
           $final = $something->queryStatement("SELECT * FROM table");
           print_r($final);
?>

 

 

Here is the main class:

 

<?php

   class login_table
   {
                       protected $_connect;
                       protected $_queryStatemet;
                       function __construct($host, $user, $pass, $database)
                       {
                               if(!$_connect = new mysqli($host, $user, $pass, $database))
                               {
                                   echo "Problem in connecting to the database.";
                               }

                       }
                       function queryStatement($_queryStatemet)
                       {
                               $this->_queryStatemet = filter_var($_queryStatemet, FILTER_SANITIZE_STRING);
                               $stmt = $this->_prepareStatement();    
                               $stmt->execute();
                               $stmt->store_result;
                               return $stmt;
                       }
                       protected function _prepareStatement()
                       {
                           if(!$ps = $this->_connect->[b]prepare([/b]$this->_queryStatemet))
                           {
                               die("No preparation.");
                           }
                           return $final;
                       }
   }


?>

You never assign your class's _connect variable.

 

This line:

if(!$_connect = new mysqli($host, $user, $pass, $database))

 

should be:

if(!$this->_connect = new mysqli($host, $user, $pass, $database))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.