简体   繁体   English

sqlsrv连接字符串无效[87]

[英]sqlsrv connection string not valid [87]

Set up: 设定:

  • Wamp Server Wamp服务器
  • PHP 5.5.12 PHP 5.5.12
  • Apache 2.4.9 阿帕奇2.4.9
  • MS SQL Server 2012 MS SQL Server 2012

Already completed: 已经完成:

  • Installed (unofficial) php_sqlsrv_55_ts and php_pdo_sqlsrv_55_ts AND confirmed they are working via phpinfo() sqlsrv_link 安装(非官方) php_sqlsrv_55_tsphp_pdo_sqlsrv_55_ts并确认它们正在通过phpinfo() sqlsrv_link正常工作
  • I have made sure that TCP/IP is enabled in SQL Configuration Manager 我已确保在SQL配置管理器中启用了TCP / IP
  • I have tested credentials in SQL Management Studio AND via ODBC in Administrrative Tools 我已经在SQL Management Studio中以及通过管理工具中的ODBC测试了凭据
  • IIS is disabled IIS已禁用

Additionally, I did have trouble with SQL Reporting Service taking port 80. This was giving me a problem with Apache, so I directed SQL Reporting Service to use port 8081. 此外,使用端口80的SQL Reporting Service确实遇到了麻烦。这给我带来了Apache的问题,因此我指示SQL Reporting Service使用端口8081。

<?php
$server = "computer_name\MSSQLSERVER";
$user = "sa";
$pass = "password";
$db = "pcm";
$connInfo = array("Database"=>$db, "UID"=>$user, "PWD"=>$pass);
$conn = sqlsrv_connect($server, $connInfo) or die( print_r( sqlsrv_errors(), true));
?>

If you are using the PDO extension, you will have to use a PDO connection instead of the sqlsrv_connect() function. 如果使用的是PDO扩展名,则必须使用PDO连接而不是sqlsrv_connect()函数。 Microsoft doesn't support the UID or PWD keys that you are providing when trying to connect via the PDO extension. 当尝试通过PDO扩展名进行连接时,Microsoft不支持您提供的UIDPWD密钥。 Try this instead: 尝试以下方法:

$conn = new PDO('sqlsrv:Server = ' . $server . '; Database = ' . $db, $user, $pass);

http://php.net/manual/en/ref.pdo-sqlsrv.connection.php http://php.net/manual/en/ref.pdo-sqlsrv.connection.php

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

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