douhuan6157 2016-09-25 10:29
浏览 40

symfony 2.8.8如何检查框架连接到mysql(mariadb)

I am using Symfony 2.8.8. framework and am quite hooked onto it for developing my first web application. The symfony book is very useful. I am on the database and doctrine chapter.

The question I have is: Is there a simple way to know that the database is functional and symfony is able to connect to the database before writing the doctrine class files that generate the database/entities?

I am using the following environment:

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

  • 写回答

1条回答 默认 最新

  • download1002 2016-09-26 11:24
    关注

    Try using this. I'm not sure if its the same for mariadb.

    Create a controller and past this inside the controller.

    $entityManager = $this->getEntityManager() ;
    
    try {
    $entityManager->getConnection()->connect();
    } catch (\Exception $e) {
    // failed to connect
    }
    

    [EDITED]

    I did some research and it seems like getEntityManager(); is deprecated since 2.3

    You can use

    // Get the entity manager
       $em = $this->getDoctrine()->getManager();
    // Connection will be written as
       $em = $this->getDoctrine()->getConnection();
    

    Or

    Check this documentation Doctrine connection

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大