我使用的是 Symfony 2.8.8。我非常迷恋它来开发我的第一个 Web 应用程序。 symfony 的书非常有用。我正在研究数据库和 Doctrine 章节。
我的问题是:在编写生成数据库/实体的 Doctrine 类文件之前,有没有一种简单的方法可以知道数据库功能正常并且 symfony 能够连接到数据库?
我正在使用以下环境:
PHP: 5.5.38 cli,
SYMFONY: 2.8.8,
DATABASE: mariadb 10.0.17 installed through XAMPP v5.6.23. launched using XAMPP control panel 3.2.2,
WEBSERVER: php internal web server with loading of php.ini file.
INI:php.ini uncommented extension=php_mysql.dll, extension=php_pdo_mysql.dll. Updated parameters.yml to point to hosted mariadb.Updated config.yml to use pdo_mysql driver
OS: windows 7
最佳答案
尝试使用这个。我不确定 mariadb 是否也一样。
创建一个 Controller 并将其粘贴到 Controller 内。
$entityManager = $this->getEntityManager() ;
try {
$entityManager->getConnection()->connect();
} catch (\Exception $e) {
// failed to connect
}
[已编辑]
我做了一些研究,看起来像 getEntityManager();自 2.3 起已弃用
您可以使用
// Get the entity manager
$em = $this->getDoctrine()->getManager();
// Connection will be written as
$em = $this->getDoctrine()->getConnection();
或者
查看此文档 Doctrine connection
关于php - symfony 2.8.8 如何检查框架连接到mysql(mariadb),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39685852/