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

  • SEARCH
  • Home
  • 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 7966859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:32:46+00:00 2026-06-04T06:32:46+00:00

What I want to do is this: class DB extends mysqli { … }

  • 0

What I want to do is this:

class DB extends mysqli {
 ...
}

DB :: connect( ... );

DB :: query( "SELECT * FROM myDB" );

class AnotherClass {
  function helloWorld()
  {
     DB :: query( "SELECT * FROM withoutUsingGlobalKeyword" );
  }
}

function functions()
{
    DB :: query( "SELECT * FROM withoutUsingGlobalKeyword" );
}

The point of this question is to avoid the use of the ‘global’ keyword like:

global $mysqli;
$mysqli = new mysqli( ... );

class AnotherClass {
   function helloWorld()
   {
      global $mysqli;
      $mysqli->query( "SELECT * FROM IDontWantToUseGlobalKeyword" );
   }
}

function functions()
{
    global $mysqli;
    $mysqli->query( "SELECT * FROM IDontWantToUseGlobalKeyword" );
}

A solution for this is to declare the mysqli variable in the $_ENV array, but I don’t want to use $_ENV to manage the MYSQLI, I want to use a static class like DB (Is that possible?)

  • 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-04T06:32:51+00:00Added an answer on June 4, 2026 at 6:32 am

    After of all, I found a solution:

    global $mysqli;
    $mysqli = new mysqli( ... );
    
    class DB  {
      public static function getConnection()
      {
         global $mysqli;
         return $mysqli;
      }
     ...
    }
    
    
    
    $mysqli->query( "SELECT * FROM myDB" );
    
    class AnotherClass {  
      function helloWorld()
      {
         $db = DB :: getConnection();
         $db->query( "SELECT * FROM withoutUsingGlobalKeyword" );
      }
    }
    
    class DBAccess {
       public $db;
       function __construct()
       {
          $this->db = DB :: getConnection();
       }
    }
    
    class MultipleMethodDBSupport extends DBAccess {
       function __construct()
       {
           parent :: __construct();
       }
    
       function m1()
       {
          $this->db->query( "SELECT * FROM withoutUsingGlobalKeyword" );
       }
    
       function m2()
       {
          $this->db->query( "SELECT * FROM withoutUsingGlobalKeyword" );
       }
    }
    
    function functions()
    {
        $db = DB :: getConnection();
        $db->query( "SELECT * FROM withoutUsingGlobalKeyword" );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do something like this: class Cls { function fun($php) { return
I have a class extends ViewGroup and want to get every MotionEvent from it.
I have one PHP class thus: class DB extends mysqli{ public function __construct( {
I have custom db class which extends MySQLi class MySQLi->query() method returns obejct with
I am creating one parent Activity(Class) and then want to extends this class to
This is sample of my code. class SomeClass extends SomeOtherClass { function __construct($input) {
I want to serialize this class: public class CarDisplay { public string Name {
i want to serialize this class, to store it on the sdcard of the
What I want is this behavior: class a: list = [] x = a()
With Django models, I want to achieve this: class Foo(models.Model): name = models.CharField(max_length=50) #wrapping

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.