Help with a class method in PHP
<p>I am trying to make a function I can pass an mysql query into and get the result back or an error, it should also check to see if the user running the code is an admin, if they are then it will get a session variable that holds a number count of the mysql queries ran on the page and then increment it by 1 number and then set it back to a session, also if the user is an admin it will show any error messages.  </p>

<p>I know it is not the best code but does it appear like it should work?  Any tips to improve too please.</p>

<p>You can see that I am running another method that gets a session variabls value, I then set it to a variable in the current method, I then increment it's value by 1 number and then run the setter method to save it to a session again.  I am not really sure If that is the correct way of doing that?  DO I really need to run all those methods and save them all to a local variable like I am?</p>

<p>Also I am getting this error<br>
Fatal error: Using $this when not in object context in C:\webserver\htdocs\project2\includes\classes\Database.class.php on line 37</p>

<p>Line 37 is this  </p>

<pre><code>$this-&gt;user_role = $session-&gt;get('user_role');
</code></pre>

<p>method...</p>

<pre><code>public static function query($sql)
{
    global $session; // the $session Object

    //get the session value to see if user is an admin
    $this-&gt;user_role = $session-&gt;get('user_role');

    //if user is admin, get query counter session value and +1 to it and reset it to a session variable.
    if ($this-&gt;user_role &gt;= 9){
        $this-&gt;querie_counter = $session-&gt;get('querie_counter');
        $this-&gt;querie_counter++; // add +1 to the number
        $session-&gt;set('querie_counter',$this-&gt;querie_counter)
    }

    //run mysql query
    $result = mysql_query($sql);

    if (!$result) {
        // If admin is viewing then we show the sql code and the error returned
        if($this-&gt;user_role &gt;= 9){
            $error = '&lt;BR&gt;&lt;center&gt;&lt;font size="+1" face="arial" color="red"&gt;An Internal Error has Occured.&lt;BR&gt; The error has been recorded for review&lt;/font&gt;&lt;/center&gt;&lt;br&gt;';
            $sql_formatted = highlight_string(stripslashes($sql), true);
            $error .= '&lt;b&gt;The MySQL Syntax Used&lt;/b&gt;&lt;br&gt;' . $sql_formatted .
            '&lt;br&gt;&lt;br&gt;&lt;b&gt;The MySQL Error Returned&lt;/b&gt;&lt;br&gt;' . mysql_error();
        }
        die($error);
    }
    return $result;
}
</code></pre>
