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"

4
  • You have two different php.ini files on your system. Run php --ini and compare it to the path listed via phpinfo Commented Feb 16, 2017 at 1:15
  • @cerad, both show /etc/php/7.0/cli/php.ini as the loaded config file Commented Feb 16, 2017 at 1: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 Commented Feb 16, 2017 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? Commented Feb 16, 2017 at 13:22

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

I had, but this got me to the solution nonetheless. Turns out you can't directly set a driver to "dblib", but this link creates a driver class you can use instead. Thanks for getting me there, marking this correct
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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.