Boa noite,
Gostaria de abrir o banco de dados no SQL Server, como faço para abrir utilizando a Classe EntityManagerCreator? Precisa também de alguma configuração no php.ini?
Mas apresenta erro. Segue o seguinte erro: Fatal error: Uncaught PDOException: could not find driver in C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:27 Stack trace: #0 C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php(27): PDO->construct('sqlsrv:server=l...', 'sa', '', Array) #1 C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOSqlsrv\Connection.php(21): Doctrine\DBAL\Driver\PDOConnection->construct('sqlsrv:server=l...', 'sa', '', Array) #2 C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOSqlsrv\Driver.php(22): Doctrine\DBAL\Driver\PDOSqlsrv\Connection->__construct('sqlsrv:server=l...', 'sa', '', Array) #3 C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php(356): Doctrine\DBAL\Driver\PDOSqlsrv\Driver->connect(Array, 'sa', '', Array) #4 C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrin in C:\Users\André Luiz\Documents\site\projeto\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php on line 31
Segue o código: namespace Alura\Cursos\Infra;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Tools\Setup;
class EntityManagerCreator { public function getEntityManager(): EntityManagerInterface { $paths = [DIR . '/../Entity']; $isDevMode = false;
$dbParams = array(
'driver' => 'pdo_sqlsrv',
'host' => 'localhost',
'dbname' => 'CURSOS',
'user' => 'sa',
'password' => ''
);
$config = Setup::createAnnotationMetadataConfiguration(
$paths,
$isDevMode
);
return EntityManager::create($dbParams, $config);
}
}