Using $this when not in object contex
<p>I'm sure this must be a simple answer but I'm just not seeing it. I'm experimenting with moving all my database code into a class for the sake of simplifying all the rest of my code.</p>

<p>I have run into this error and I can't see why</p>

<p>Fatal error: Using $this when not in object context in /var/www/php/dbclass.php on line 18 (I've marked line 18 with an arrow)</p>

<p>Here is my class</p>

<pre><code>&lt;?php

class kdb {

    var $dbhost = "localhost";
    var $dbname = "name";
    var $dbuser = "root";
    var $dbpass = "pass";

    var $error;

//    function __construct($persons_name) {
//        $this-&gt;name = $persons_name;
//    }
    //function to insert safely

    public static function exe($qry_string, $var_array) {
        $host = $this-&gt;dbhost;  &lt;------------------ LINE 18
        $name = $this-&gt;dbname;
        $user = $this-&gt;dbuser;
        $pass = $this-&gt;dbpass;
        $retries = 30;
        while ($retries &gt; 0) {
            try {
                $pdo_conn = new PDO("mysql:host={$host};dbname={$name}", $user, $pass);
                $retries = 0;
                //echo 'run query';
            } catch (PDOException $e) {
                $retries--;
                sleep(1); // Wait 1s between retries.
                log::enter_log("Error connecting: {$retries} retries left");
            }
        }
        $q = $pdo_conn-&gt;prepare($qry_string);
        $q-&gt;execute($var_array);
        $return_arr = $q-&gt;fetchAll();
        $this-&gt;error = $q-&gt;errorInfo();
        //dbconn::logquery($qry_string, $var_array, $q-&gt;rowCount(), $error[2]);
        return $return_arr;
    }

}

?&gt;
</code></pre>

<p>and the code on the page</p>

<pre><code>    $db = new kdb();   
    $db_list = $db-&gt;exe('select * from table where id = ?', array(42));
    var_dump($db_list);
</code></pre>

<p>Please be aware it is only half finished, I am aware that at the moment it is more complicated than it needs to be.</p>
