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 8846345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:57:37+00:00 2026-06-14T11:57:37+00:00

Apparently My database function can’t fetch the database? Warning: mysqli::real_escape_string(): Couldn’t fetch database I’ve

  • 0

Apparently My database function can’t fetch the database?

Warning: mysqli::real_escape_string(): Couldn’t fetch database

I’ve created a custom database class which extends MySQLi.

Here’s how I’m constructing it.

public function __construct(){
    $db = new mysqli(
        DB_HOST, DB_USER, DB_PASS, DB_NAME);

    $db->select_db(DB_NAME);
    return $db;
}

I am selecting the database, aren’t I?

The code where this is happening is here:

    private static function readSession($sessionId)
    {
    global $database;
    $sessionId = session_id();
    $sessionId = $database->real_escape_string($sessionId);
    $time = time();
    $result = $database->query("SELECT sessiondata FROM sessions WHERE sessionid='$sessionId' AND expiry > $time");
    if ($result->num_rows > 0) {
        $row = $result->fetch_array();
        return $row['sessiondata'];
    }
    return "";
}

The database is being initiated before the Session Management functions are being called.

  • 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-06-14T11:57:38+00:00Added an answer on June 14, 2026 at 11:57 am

    You say that your custom class extends mysqli. If that is the case, you need to call the mysqli __construct() in your extending constructor, without returning anything:

    class YourDatabase extends mysqli {
      public function __construct() {
        // Call the mysqli constructor explictly
        parent::__construct(DB_HOST, DB_USER, DB_PASS, DB_NAME);
        // No need to call select_db() again, since default db was selected in the 
        // parent constructor
    
        // Don't return anything
        // the constructor returns $this, which extends mysqli
        return;
      }
    }
    
    // Use as:
    $database = new YourClass();
    $database->query("SELECT * FROM atable");
    

    Extending a class means that you are using a descendent of the parent class. You do not need to instantiate an instance of the parent class, but if you need to make use of its constructor and extend its functionality, you must explicitly call parent::__construct(...) in the child class’s __construct().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently there is a database postgres that is created by default on each postgresql
The BlackBerry Desktop API has the interface IRimTable which apparently maps an application database
Most databases have something like a GREATEST function, which can be useful some times.
During my work on this database application, I've apparently managed to corrupt a form
Apparently MapReduce queries are one of the slowest things one can do in MongoDB
Apparently (at least according to gcc -std=c99 ) C99 doesn't support function overloading. The
I have an Sqlite database in which I want to select rows of which
In Oracle and MySQL, how can I create a function that takes an indefinite
I have got a problem where my class apparently is not being parsed correctly
The following function is set up to: Collect the user_id from my database, as

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.