-1

Fatal error: Call to a member function bind_param() on a non-object in on /* Line80 error:

 function write($id, $data) {
           // Get unique key
           $key = $this->getkey($id);
           // Encrypt the data
           $data = $this->encrypt($data, $key);

           $time = time();
           if(!isset($this->w_stmt)) {
              $this->w_stmt = $this->db->prepare("REPLACE INTO sessions (id, set_time, data, session_key) VALUES (?, ?, ?, ?)");
           }

        /* Line80 error: */  $this->w_stmt->bind_param('siss', $id, $time, $data, $key);
           $this->w_stmt->execute();
           return true;
        }
reza jafari
  • 1,228
  • 13
  • 14
  • Because you're not binding 'siss' – Daan Aug 15 '14 at 10:27
  • Nevermind read to fast. – Daan Aug 15 '14 at 10:29
  • So, you called `bind_param` on `$this->w_stmt` and it says it's not an object. Then you look closely and you see that you only check whether `$this->w_stmt` is set, not whether it's an instance of mysqli or whether it's an object. Therefore, check what `$this->w_stmt` is before you assume that it's an object. – N.B. Aug 15 '14 at 10:29
  • 1
    can you show a table structure for this schema ? – Abdou Tahiri Aug 15 '14 at 10:31

2 Answers2

0

I don't see any error here. I think you have set variable somewhere in your class, for example as property:

<?php


class A
{
    private $x = '';

    public function show()
    {
        if (!isset($this->x)) {
            echo "was not set";
        }
    }
}

$a = new A();
$a->show();

In this code no echo will be displayed, because property $x is set and assigned empty string.

So in your case this line:

$this->w_stmt = $this->db->prepare("REPLACE INTO sessions (id, set_time, data, session_key) VALUES (?, ?, ?, ?)");

is probably never executed.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
0

The error is pretty self-explanatory. $this->w_stmt isn't an object. You'll have to make sure that $this->w_stmt is an object before you attempt to call the function bind_param.

My guess is that $this->w_stmt is set (it exists), but it isn't an object.

Try something like:

if(!isset($this->w_stmt) || !($this->w_stmt instanceof PDOStatement)) {
    $this->w_stmt = $this->db->prepare("REPLACE INTO sessions (id, set_time, data, session_key) VALUES (?, ?, ?, ?)");
}
Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66