douchen1924 2013-11-18 12:09
浏览 23
已采纳

配置PHP 5.3以使用MS SQL Server

I've been tasked with taking all of our MySQL databases and migrating them to SQL Server. In attempting to get PHP 5.3.24 to work with MSSQL, I've done the following:

Copied the non thread-safe drivers to /php/ext.

Updated my php.ini file to include the following two lines:

extension=php_pdo_sqlsrv_53_nts_vc9.dll;
extension=php_sqlsrv_53_nts_vc9.dll

Restarted IIS 7 running on Windows Server 2008 R2.

phpinfo shows sqlsrv under Registered PHP Streams, and sqlsrv also appears under PDO drivers and pdo_sqlsrv support shows as "enabled." 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. What have I missed?

EDIT: Configure Command under phpinfo shows the lines "--without-mssql" "--without-pdo-mssql". I don't know where to go to change this, or if it's necessary.

  • 写回答

1条回答 默认 最新

  • dsf1222 2013-11-18 12:28
    关注

    You're using an invalid DSN connection string for MSSQL. You need to use the format found here.

    new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx,1433;Database=mydb', 'user', 'pwd');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下