I am creating a class that uses PDO, but in a namespace other than global:
namespace Classes\Config;
use \PDO;
class Connection {
public static function getConnection() {
$dbhost = "algumhost";
$dbuser = "algumuser";
$dbpass = "algumasenha";
$dbname = "algumabase";
$dbms = "algumsgbd";
$dbport = "9999";
$dsn = "$dbms:host=$dbhost;port=$dbport;dbname=$dbname;user=$dbuser;password=$dbpass";
try {
$dblink = new PDO ( $dsn );
$dblink->setAttribute ( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch ( PDOException $e ) {
echo 'Erro na conexão: ' . $e->getMessage();
}
return $dblink;
}
}
After trying to use the getConnecton method, I get this error:
Fatal error: Class 'Classes\PDO' not found in path/para/meuarquivo.php on line 69
Does anyone know what I might be doing wrong? Thanks in advance.
Q: I use the composer to autoload my project.