问题
I'm trying to connect to my database in SQL Server 2000, but i get an error
could not find driver
when i'm using pdo_sqlsrv. But if i use sqlsrv i get an error
Attempted to call function "sqlsrv_configure" from namespace "Doctrine\DBAL\Driver\SQLSrv".
Here is my config.yml
config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
host: "%database_host%"
driver: pdo_mysql
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
connection2:
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
host: "%database_host2%"
driver: pdo_sqlsrv
#driver: sqlsrv i've also tried this
#charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
Does anybody know why i'm getting these errors?
回答1:
If the function sqlsrv_configure can't be found, then the sqlsrv extension isn't installed. It can be found on the official Microsoft repository here.
You can check if you've installed the extension by running the command php -m
in your terminal. Note that if you're running Symfony on a standalone server (eg MAMP, XAMP, or anything else that uses a non-CLI version of PHP) then the extensions used by the CLI and the standalone server may differ.
You can test this by going to the profiler in Symfony (/_profiler
by default) and clicking on the "View full PHP configuration" link under the Configuration
menu item. This will open the phpinfo()
screen. Look for either the sqlsrv
or pdo_sqlsrv
extensions there.
EDIT
Looking at the Doctrine docs again, it seems that pdo_sqlsrv
causes problems. Doctrine recommends using sqlsrv
.
pdo_sqlsrv
: A Microsoft SQL Server driver that usespdo_sqlsrv
PDO Note that this driver caused problems in our tests. Prefer the sqlsrv driver if possible.
(Emphasis not mine)
回答2:
Can you try:
driver: pdo_sqlsrv
database_port: 1433
Not sure if that will work, but try it.
来源:https://stackoverflow.com/questions/45196492/connection-to-a-db-with-doctrine-pdo-sqlsrv