Help with a class method in PHP

2shardDt5

New Member
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. I know it is not the best code but does it appear like it should work? Any tips to improve too please.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?Also I am getting this error
Fatal error: Using $this when not in object context in C:\webserver\htdocs\project2\includes\classes\Database.class.php on line 37Line 37 is this \[code\]$this->user_role = $session->get('user_role');\[/code\]method...\[code\]public static function query($sql){ global $session; // the $session Object //get the session value to see if user is an admin $this->user_role = $session->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->user_role >= 9){ $this->querie_counter = $session->get('querie_counter'); $this->querie_counter++; // add +1 to the number $session->set('querie_counter',$this->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->user_role >= 9){ $error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review</font></center><br>'; $sql_formatted = highlight_string(stripslashes($sql), true); $error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted . '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error(); } die($error); } return $result;}\[/code\]
 
Back
Top