简体   繁体   English

无法使用 PHP 连接到 SQL 服务器

[英]Unable to connect to SQL Server with PHP

Connection to sqlsrv string not working.sqlsrv字符串的连接不起作用。

$login = new PDO("sqlsrv:server=MYSQLSERVER\SQLEXPRESS;Database=db_name", "user", "passw");

And i have error message: Fatal error: Invalid handle returned .我有错误消息: Fatal error: Invalid handle returned

I'm 101% sure that login details is OK.我 101% 确定登录详细信息是正确的。 Because it works on other projects.因为它适用于其他项目。 Could be a problem PHP 7 ?可能是问题PHP 7

Try "ConnectionPooling=0" in DSN. 在DSN中尝试“ConnectionPooling = 0”。

sometimes working and sometimes return error 有时工作,有时返回错误

It might be a problem on re-using connection. 重新使用连接可能是一个问题。

DSN Reference: https://msdn.microsoft.com/en-us/library/ff628167(v=sql.105).aspx DSN参考: https//msdn.microsoft.com/en-us/library/ff628167(v = sql.105) .aspx

There's a problem with PHP Sql Server driver PHP Sql Server驱动程序存在问题
You should update it to new version 您应该将其更新为新版本

As you mentioned you are using windows, this version is fully working on windows 如你所说,你正在使用Windows,这个版本完全适用于Windows

https://github.com/Microsoft/msphpsql/releases/tag/v4.1.1-Windows https://github.com/Microsoft/msphpsql/releases/tag/v4.1.1-Windows

Looks like to connect to MS-SQL, you will need to utilize ODBC. 看起来要连接到MS-SQL,您将需要使用ODBC。

Reference: http://php.net/manual/en/pdo.construct.php#120705 参考: http//php.net/manual/en/pdo.construct.php#120705

$odbc="odbc:Driver={SQL Server};Server=$server;Database=$database;";

$cnx = new PDO( $odbc , $user, $password);

i updated windows php 7 drivers我更新了 windows php 7 个驱动程序

and solved:)并解决了:)

https://github.com/microsoft/msphpsql/releases/tag/v4.1.1-Windows https://github.com/microsoft/msphpsql/releases/tag/v4.1.1-Windows

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

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