I have a class called MinPDO
and inside it a function called connect
:
class MinPDO {
public $sgbd = "mysql";
public $dbhost = "localhost";
public $dbname = "minpdo";
public $dbuser = "root";
public $dbpass = "";
public function connect() {
try {
$conn = new PDO("{$this->sgbd}:host={$this->dbhost};dbname={$this->dbname};charset=utf8;", $this->dbuser, $this->dbpass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
return $conn;
} catch (PDOException $ex) {
echo "<br><b>Error:</b> " . $ex->getMessage();
return false;
}
}
}
How can I call it that?
MinPDO::connect();
I'm currently doing this:
$mnpdo = new MinPDO();
$mnpdo->connect();
According to some programmers it would be more useful to call it the first form, but how do I do it?