我正在尝试与PHP和MS SQL Server 2005建立连接。我在Windows 8和PHP版本5.3.28中使用IIS 8。我已经做了我的研究,我找到了MSSQL PHP PDO (http://www.php.net/manual/en/ref.pdo-sqlsrv.connection.php和http://technet.microsoft.com/en-us/library/ff754357(v=sql.105).aspx),下载并启用了我从微软网站(Microsoft Drivers 3.0 for PHP for SQL Server)找到的所有与PDO相关的dll,并确保它们反映在phpinfo()中。
extension=php_pdo_sqlsrv_52_nts_vc6.dll
extension=php_pdo_sqlsrv_53_nts.dll
extension=php_pdo_sqlsrv_53_nts_vc6.dll
extension=php_pdo_sqlsrv_53_nts_vc9.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_sqlsrv_54_nts.dll
extension=php_sqlsrv_53_ts_vc9.dll
Stock Over Flow中的以下链接也为我的困境提供了很大帮助:
- 使用SQL Server Driver通过PDO连接到SQL Server 使用SQLSrv和PHP 5.4.7连接MSSQL错误
- 我如何连接到Sql Server从Mac与PHP PDO?
- 通过php和linux使用pdo连接mssql
我能够修复"未找到驱动程序"one_answers"连接字符串无效"的问题,这是我目前的PHP代码:
$db_server = "func.website.com,8787";
//$db_server = "func.website.com:8787sqlexpress";
$db_database = "db_BreadNButter";
$db_user = "tinapay";
$db_passwd = "p@ssword";
try {
//$db = new PDO ("mssql:host=$db_server;dbname=$db_database;", $db_user, $db_passwd);
$db = new PDO ("sqlsrv:Server=$db_server;Database=$db_database;", $db_user, $db_passwd);
} catch(PDOException $exception) {
die("Unable to open database.<br>Error message:<br><br>$exception.");
}
我认为(手指交叉),我已经建立了连接到MSSQL DBase,但我得到下面的错误:
exception 'PDOException' with message 'SQLSTATE[08001]:
[Microsoft][SQL Server Native Client 11.0]TCP Provider: Timeout error [258].
' in C:inetpubwwwrootbreadnbutterclass.connection.php:12 Stack trace: #0
C:inetpubwwwrootbreadnbutterclass.connection.php(12):
PDO->__construct('sqlsrv:Server=f...', 'tinapay', 'p@ssword') #1 {main}.
谁能告诉我为什么我得到超时错误,我怎么能解决这个问题?
端口应为func.website.com:8787
。你的逗号打错了
如何在PHP 5.4.4中连接SQLSRV 2008埃罗是:数组([0] =>数组([0] [au:[sqlstate] => imssp . exe[1] => -49[code] => -49[2] =>此扩展需要Microsoft SQL Server 2012本地客户端。x86版本的Microsoft SQL Server 2012 Native Client ODBC驱动程序下载地址:http://go.microsoft.com/fwlink/?LinkId=163712[message] =>此扩展需要Microsoft SQL Server 2012本地客户端。x86版本的Microsoft SQL Server 2012 Native Client ODBC驱动程序下载地址:http://go.microsoft.com/fwlink/?LinkId=163712)
[1] => Array
(
[0] => IM002
[SQLSTATE] => IM002
[1] => 0
[code] => 0
[2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
[message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
)
)
我仍然有这个问题,但我能够说服我的老板使用asp而不是PHP。非常感谢那些帮助我的人。