What's happening
I created a static method to return the connection so that I can use it in DAO, but doing so gives Class Not Found PDO .
OtherProjects
Thefirstthingthatmanypeoplewillthinkis,"The extension is not activated." Sirs, the extensions are properly activated and have already been used in other projects. I have here 2 other projects with the PDO, but this time I tried to use Object Orientation in the best possible way, to make the code more clean.
OBS:
If anyone has any suggestions for leaving some class more 'beautiful', I will be open to modifications.
Active PDO
My Code
Class EntityDAO
<?php
namespace Presto\model;
use Presto\model\ConnectionFactory as ConnectionFactory ;
class EntidadeDAO {
private $connection = null;
public function __construct() {
self::$connection = ConnectionFactory::getConnection();
}
}
Class ConnectionFactory
<?php
namespace Presto\model;
class ConnectionFactory {
public static function getConnection() {
$connection = null;
$config = self::configureConnection();
try {
self::$conection = new PDO($config['databaseType'].':host='.$config['hostname'].';dbname='.$config['database'],$config['username'],$config['password']);
}catch (PDOException $e) {
echo $e->getMessage();
}
return self::$connection;
}
public static function configureConnection() {
$config = array();
$config['databaseType'] = 'pgsql';
$config['hostname'] = '127.0.0.1';
$config['database'] = 'minhaDatabase';
$config['username'] = 'root';
$config['password'] = 'password';
return $config;
}
}