Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 560031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:18:00+00:00 2026-05-13T12:18:00+00:00

I am trying to make a function I can pass an mysql query into

  • 0

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 variables 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 37

Line 37 is this

$this->user_role = $session->get('user_role');

Method…

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 occurred.<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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:18:01+00:00Added an answer on May 13, 2026 at 12:18 pm

    Hmm no one has read the error or?

    **Fatal error: Using $this when not in object context in C:\webserver\htdocs\project2\includes\classes\Database.class.php on line 37**
    

    ok you cant use $this in a static function you have to use self::users

    public static function query($sql)
    {
        global $session; // the $session Object
    
        //get the session value to see if user is an admin
        self::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 (self::user_role >= 9){
            self::querie_counter = $session->get('querie_counter');
            self::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(self::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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying to make a autoscrolling/carousel like function for an unordered list of images.
Trying to make a make generic select control that I can dynamically add elements
I am trying to make a div, that when you click it turns into
Trying to make a generic PL/SQL procedure to export data in specific XML format,
Trying to make a web service call to an HTTPS endpoint in my Silverlight
I'm trying to make the case for click-once and smart client development but my
I'm trying to make a data bound column invisible after data binding, because it
I'm trying to make a context menu for a control that is linked to
I am trying to make a JTable that has column spans available. Specifically, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.