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

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?