I am looking at creating an object that is called upon to pass data to the data store. My implementation uses MySQLi, but I want to allow other developers to use whatever data store they want.
I was thinking that a static method might be the best answer, but not having any familiarity with them I am unsure if I would be actually creating lots of connections or reusing the same one.
<?php
class RECORDS {
protected $conn;
public function __construct() {
//contect to DB
$conn = $this::connection();
}
public static function &connection(){
$conn = NULL;
if($conn==NULL){
$conn = new mysqli(_DB_HOST_, _DB_USER_, _DB_PASS_, _DB_HOST_);
if ($mysqli->connect_errno) {
die("Failed to connect to MySQL: (" .
$mysqli->connect_errno . ") " .
$mysqli->connect_error);
}
}
return $conn;
}
// ... methods that do stuff
}
Have I got the right idea about static methods and will I be reusing the same connection or making new ones?