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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:28:27+00:00 2026-05-27T19:28:27+00:00

MySQLi works fine inside a class with no namespace and outside a class. I

  • 0

MySQLi works fine inside a class with no namespace and outside a class.

I recently started using namespace and now I have stumbled on a code much like the following:

 namespace Project;

 class ProjectClass{

      public static function ProjectClassFunction{
          $db = new mysql(data, data, data, data);
      }

 }

However, it reports back to me with a message

"Fatal error: Class ‘Project\mysqli’ not found"

How do I use mysqli inside a class which uses namespace?

  • 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-27T19:28:27+00:00Added an answer on May 27, 2026 at 7:28 pm

    By default, PHP will try to load classes from your current namespace. Refer to the class in the global namespace:

    $db = new \mysqli(/* ... */);
    

    This is the same thing you’d do when referring to a class in a different namespace:

    $foo = new \Some\Namespace\Foo();
    

    Note that if you left off the beginning backslash, PHP would try to load the class relative to your current namespace. The following code will look in the namespace Project\Some\Namespace for a class named Foo:

    namespace Project;
    $foo = new Some\Namespace\Foo();
    

    Alternatively, you can explicitly import namespaces and save yourself ambiguity:

    namespace Project;
    
    use Mysqli;
    
    class ProjectClass
    {
        public static function ProjectClassFunction()
        {
            $db = new Mysqli(/* ... */);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this toy code, works fine, using MySQL var r = new SimpleRepository(DB,
In my code I have a file that initializes a MySQLi class. File a
I have a query which works fine in MySQL, but when I run it
I have the following query which works fine with MySQL but refuses to work
I have the following named_scope which works fine in MySQL and sqlite but bombs
I have a wrapper php class for mysqli which amongst other things needs to
I'm having a problem using methods in my module's model class. I have a
I have the following simple mysqli php application, which should work fine. $pk is
I have some django code that runs fine on a SQLite database or on
I need some help, I have created this function and it works fine, but

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.