使用Doctrine pdo_sqlsrv连接到数据库 [英] Connection to a db with Doctrine pdo_sqlsrv

查看:195
本文介绍了使用Doctrine pdo_sqlsrv连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到SQL Server 2000中的数据库,但出现错误

I'm trying to connect to my database in SQL Server 2000, but i get an error


找不到驱动程序

could not find driver

当我使用pdo_sqlsrv时。
但是如果我使用sqlsrv,我会得到一个错误

when i'm using pdo_sqlsrv. But if i use sqlsrv i get an error


试图从命名空间
Doctrine中调用函数 sqlsrv_configure \DBAL\Driver\SQLSrv。

Attempted to call function "sqlsrv_configure" from namespace "Doctrine\DBAL\Driver\SQLSrv".

这是我的config.yml

Here is my config.yml

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?

推荐答案

如果找不到函数sqlsrv_configure,则说明未安装sqlsrv扩展名。可以在官方Microsoft资源库中找到此处

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.

您可以通过在终端中运行命令 php -m 来检查是否安装了扩展程序。请注意,如果您在独立服务器(例如MAMP,XAMP或使用非CLI版本的PHP的任何其他服务器)上运行Symfony,则CLI和独立服务器使用的扩展名可能会有所不同。

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.

您可以通过以下方法进行测试:转到Symfony中的探查器(默认为 / _ profiler ),然后单击查看完整的PHP配置。 配置菜单项下的链接。这将打开 phpinfo()屏幕。在此处查找 sqlsrv pdo_sqlsrv 扩展名。

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.

编辑

查看文档再次显示,似乎 pdo_sqlsrv 会引起问题。教义建议使用 sqlsrv

Looking at the Doctrine docs again, it seems that pdo_sqlsrv causes problems. Doctrine recommends using sqlsrv.


pdo_sqlsrv :使用 pdo_sqlsrv PDO的Microsoft SQL Server驱动程序请注意,此驱动程序在我们的测试中引起了问题。尽可能使用sqlsrv驱动程序。

pdo_sqlsrv: A Microsoft SQL Server driver that uses pdo_sqlsrv PDO Note that this driver caused problems in our tests. Prefer the sqlsrv driver if possible.

(强调不是我的)

这篇关于使用Doctrine pdo_sqlsrv连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆