Jump to content

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


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

Edited by kicken
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.