简体   繁体   English

在Symfony中的PHP和从命令行运行的php正在加载不同的驱动程序

[英]Php in Symfony and php run from the command line are loading different drivers

I am trying to connect to a remote sql server, and have succeeded in doing so from the command line. 我正在尝试连接到远程sql服务器,并已从命令行成功完成连接。 When running php -i | grep PDO 当运行php -i | grep PDO php -i | grep PDO I get 我得到的php -i | grep PDO

PDO
PDO support => enabled
PDO drivers => sqlsrv, dblib, mysql
PDO Driver for FreeTDS/Sybase DB-lib => enabled
PDO Driver for MySQL => enabled`

When running a php script from the command line, I can connect to the remote DB no problem. 从命令行运行php脚本时,我可以连接到远程DB没问题。 When running that exact same code in my Symfony application, I get 在我的Symfony应用程序中运行完全相同的代码时,我得到

[Doctrine\DBAL\Driver\PDOException]                              
SQLSTATE[01002] Adaptive Server connection failed (severity 9) 

When I run phpinfo() in Symfony, the only PDO driver that comes up is mysql 当我在Symfony中运行phpinfo()时,出现的唯一PDO驱动程序是mysql

When I run phpinfo() from the command line, I get mysql, sqlsrv, and dblib 当我从命令行运行phpinfo() ,我得到了mysql,sqlsrv和dblib

Why are some pdo drivers not loading in Symfony? 为什么某些pdo驱动程序无法在Symfony中加载?

Edit: The DB is configured properly in Symfony as php bin/console doctrine:query:sql "SELECT * FROM my_table" returns results. 编辑:数据库已在Symfony中正确配置为php bin/console doctrine:query:sql "SELECT * FROM my_table"返回结果。 The same query executed in Symfony errors with "could not load driver" 在Symfony错误中执行的同一查询带有“无法加载驱动程序”

Did you mention those pdo drivers in the app/config.yml file in your symfony project ? 您在symfony项目的app / config.yml文件中是否提到了这些pdo驱动程序?

You need to tell symfony ( that means write it in the config.yml file ) about those drivers in order for him to recognize and use them. 您需要告诉symfony这些驱动程序(这意味着将其写在config.yml文件中),以便他识别和使用它们。

Check out this topic, it may help you, it is about using a mysql pdo driver and a postgresql pdo driver 查看本主题,它可能对您有帮助,它与使用mysql pdo驱动程序和postgresql pdo驱动程序有关

Use a postgres database with symfony3 将postgres数据库与symfony3一起使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM