php - Any performance issues with passing in a db connection object each time I instantiate a class? -


many of classes require access database work. while i've been doing following:

// create (one) database object $mysqli = new mysqli("host", "username", "password", "db");  // pass database object each new object requires database interaction follows $car = new car($data, $mysqli); $plane = new plane($data, $mysqli); // etc 

then each class has private $mysqli member passed in mysqli object assigned in construct follows:

class car {      private $mysqli;      public function __construct($data, $mysqli) {          $this->mysqli = $mysqli;      }  } 

then class methods can use mysqli object this:

public function fuellevel() {      $this->mysqli->query("select fuel_level fuel_tank");  } 

my question is, run performance issues if create few thousand of these objects? correct in thinking there technically 1 database connection in entire application doing so? or should using references (pointers?) below avoid feared performance overheads?

$car = new car($data, &$mysqli); $plane = new plane($data, &$mysqli); 

no, cannot possibly cause measurable performance impact. correct, there single connection object you're passing reference. level of optimization isn't should concerned while developing in php.

you should absolutely not use call-time pass-by-reference (new car($data, &$mysqli)), deprecated in php 5.3.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -