I'm just getting started with OOP PHP and all of the information out there is about a car that is red or blue...it's hard to get my head around the database connection only object as such.
I have a haunting suspicion that my __construct() shouldn't have the connection string in it and instead be it's own method inside the class.. but it works so....
Is it incorrect to define my connection class like below.. If it is wrong - how should it look?
class dbConnect {
// Declare connection info for PDO
private $dbType = 'mysql';
private $dbHost = 'localhost';
private $dbUser = 'user';
private $dbPass = 'password';
private $dbName = 'db';
// Declare connection variable for object
private $dbConn;
// Construct object
private function __construct() {
// Create Database connection and assign it to object as dbConn
$this -> dbConn = new PDO( $this -> dbType . ':' . 'host=' . $this -> dbHost . ';' . 'dbname=' . $this -> dbName , $this -> dbUser , $this -> dbPass );
}
}