The system utilizes a single User class and most of the method utilize PDO to exchange the data with the database.
class User {
private $db_server;
private $db_login;
private $db_pass;
private $db;
public function method_1(){
$statement = new PDO("mysql:host=".$this->db_server.";dbname=".$this->db, $this->db_login, $this->db_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
//doing something with PDO
}
// ...
public function method_n(){
$statement = new PDO("mysql:host=".$this->db_server.";dbname=".$this->db, $this->db_login, $this->db_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
//doing something with PDO
}
}
The question is am I utilizing PDO effectively? Should I instantiate a PDO object as one of the class properties and pass it to every method that needs it, instead of instantiating a new PDO object in the method itself?