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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:39:35+00:00 2026-06-06T13:39:35+00:00

Many of my classes require access to a database to do their work. For

  • 0

Many of my classes require access to a database to do their work. For a while I’ve been doing something like the following:

// Create a (one) database object
$mysqli = new mysqli("host", "username", "password", "db");

// Pass database object into each new object that requires database interaction as follows
$car = new Car($data, $mysqli);
$plane = new Plane($data, $mysqli);
// etc

Then each class has a private $mysqli member which the passed in mysqli object is assigned to in the construct as follows:

class Car {

    private $mysqli;

    public function __construct($data, $mysqli) {

        $this->mysqli = $mysqli;

    }

}

Then class methods can use the mysqli object easily like this:

public function fuelLevel() {

    $this->mysqli->query("SELECT fuel_level FROM fuel_tank");

}

My question is, will I run into any performance issues if I were to create a few thousand of these objects? Am I correct in thinking that there is only technically one database connection in my entire application by doing so? Or should I be using references (pointers?) like below to avoid the feared performance overheads?

$car = new Car($data, &$mysqli);
$plane = new Plane($data, &$mysqli);
  • 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-06T13:39:37+00:00Added an answer on June 6, 2026 at 1:39 pm

    No, this cannot possibly cause any measurable performance impact. You are correct, there is a single connection object which you’re passing by reference. This level of optimization isn’t something you should be concerned with while developing in PHP.

    You should absolutely not use call-time pass-by-reference (new Car($data, &$mysqli)), which is deprecated in PHP 5.3.

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

Sidebar

Related Questions

I've seen many frameworks and helper classes which require you to call their base.MethodName()
I'm trying to decide whether to create many classes for each content type I
Ok so I'm doing a simulation about a Mall I have many classes in
I have a series of classes that are going to require many boolean fields,
There are many classes having this provider suffix. (Data,membership,modelmetadata,...). When should be a class
My application has many classes, worker threads, and background service operations. Notifications can come
Has anyone ever heard of overriding too many classes in Java? Perhaps this issue
I have an ASP.NET project that contains many classes. I am thinking about creating
In C#, how many classes can you inherit from? When you write: using System.Web.UI;
I'm working on a large project (for me) which will have many classes and

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.