Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to SQL Server with PHP

Connection to sqlsrv string not working.

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

And i have error message: Fatal error: Invalid handle returned.

I'm 101% sure that login details is OK. Because it works on other projects. Could be a problem PHP 7?

like image 421
Klapsius Avatar asked Jul 06 '16 11:07

Klapsius


2 Answers

Try "ConnectionPooling=0" in DSN.

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

like image 64
maydimanche Avatar answered Oct 04 '22 04:10

maydimanche


There's a problem with PHP Sql Server driver
You should update it to new version

As you mentioned you are using windows, this version is fully working on windows

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

like image 45
ReZa Avatar answered Oct 04 '22 02:10

ReZa