0

I am trying to connect to a remote sql server, and have succeeded in doing so from the command line. When running php -i | grep PDOI get

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. When running that exact same code in my Symfony application, I get

[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

When I run phpinfo() from the command line, I get mysql, sqlsrv, and dblib

Why are some pdo drivers not loading in Symfony?

Edit: The DB is configured properly in Symfony as php bin/console doctrine:query:sql "SELECT * FROM my_table" returns results. The same query executed in Symfony errors with "could not load driver"

  • You have two different php.ini files on your system. Run php --ini and compare it to the path listed via phpinfo – Cerad Feb 16 '17 at 01:15
  • @cerad, both show `/etc/php/7.0/cli/php.ini` as the loaded config file – Alex Slocum Feb 16 '17 at 01:39
  • The mods enabled can also be different. Check the /etc/php/7.0/apache or fpm or whatever folder and see if the pdo mod is enabled like it is in the cli folder – mickadoo Feb 16 '17 at 10:08
  • Just for grins, try running the builtin symfony server bin/console server:run It really should not make any difference but for some reason your server is getting the php configuration information from someplace else. Are you doing some kind of docker or vagrant thing? – Cerad Feb 16 '17 at 13:22

1 Answers1

0

Did you mention those pdo drivers in the app/config.yml file in your symfony project ?

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.

Check out this topic, it may help you, it is about using a mysql pdo driver and a postgresql pdo driver

Use a postgres database with symfony3

Community
  • 1
  • 1
paris93
  • 212
  • 1
  • 2
  • 16
  • I had, but this got me to the solution nonetheless. Turns out you can't directly set a driver to "dblib", but this [link](https://packagist.org/packages/leaseweb/doctrine-pdo-dblib) creates a driver class you can use instead. Thanks for getting me there, marking this correct – Alex Slocum Feb 16 '17 at 01:25
  • Scratch that, didn't actually get me there. I was able to connect to the DB using doctrine, but again, only from the command line using bin/console. When I run a query in the app, I get "Could not load driver" – Alex Slocum Feb 16 '17 at 01:37