简体   繁体   English

配置PHP 5.3与MS SQL Server一起使用

[英]Configuring PHP 5.3 to work with MS SQL Server

I've been tasked with taking all of our MySQL databases and migrating them to SQL Server. 我的任务是获取所有MySQL数据库并将它们迁移到SQL Server。 In attempting to get PHP 5.3.24 to work with MSSQL, I've done the following: 为了使PHP 5.3.24与MSSQL一起使用,我做了以下工作:

Copied the non thread-safe drivers to /php/ext. 将非线程安全的驱动程序复制到/ php / ext。

Updated my php.ini file to include the following two lines: 更新了我的php.ini文件,使其包括以下两行:

extension=php_pdo_sqlsrv_53_nts_vc9.dll;
extension=php_sqlsrv_53_nts_vc9.dll

Restarted IIS 7 running on Windows Server 2008 R2. 重新启动在Windows Server 2008 R2上运行的IIS 7。

phpinfo shows sqlsrv under Registered PHP Streams, and sqlsrv also appears under PDO drivers and pdo_sqlsrv support shows as "enabled." phpinfo在“已注册的PHP流”下显示sqlsrv,并且sqlsrv也在PDO驱动程序下显示,并且pdo_sqlsrv支持显示为“已启用”。 Yet, when I try to connect via my application, I get the following: 但是,当我尝试通过应用程序进行连接时,得到以下信息:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\mystuff\myphpconnectfile.php

My connect string looks like this: 我的连接字符串如下所示:

$con = new PDO("mssql:host=xxx.xxx.xxx.xxx,1433;dbname=mydb", "user", "pwd");
$con -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return($con);

Looks like it's finding the server okay, but not the PHP/PDO mssql drivers. 看起来服务器正常,但PHP / PDO mssql驱动程序不正常。 What have I missed? 我错过了什么?

EDIT: Configure Command under phpinfo shows the lines "--without-mssql" "--without-pdo-mssql". 编辑:在phpinfo下的Configure Command显示行“ --without-mssql”“-without-pdo-mssql”。 I don't know where to go to change this, or if it's necessary. 我不知道该去哪里更改它,或者是否有必要。

You're using an invalid DSN connection string for MSSQL. 您为MSSQL使用了无效的DSN连接字符串。 You need to use the format found here . 您需要使用此处找到的格式。

new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx,1433;Database=mydb', 'user', 'pwd');

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

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