After upgrading to PHP 5.4 and using CodeIgniter’s PHP framework my application refused to connect to the SQL Server 2005 database. There were no configuration changes performed, and I made sure to install the PHP SQLSRV drivers (3.0.3) as well. The specific message from CI was “Unable to connect to your database server using the provided settings”.
Switch back to PHP 5.3 and everything works.
To make sure that the sqlsrv drivers are installed on PHP 5.4 I ran php -m and it displays “sqlsrv”. phpinfo() looks good as well.
I can’t get any debug information on how/why sqlsrv isn’t connecting with the new drivers. What’s funny is that if I download sqlsrv-5.4-nts-snap.zip from this funny page of drivers on MS’s site – then it works! However it seems to be using sqlsrv 2.0 drivers.
Does SQLSRV work on PHP 5.4?
Finally debugging this issue – it turns out the issue was with the connection parameters when using TCP/IP instead of shared memory/named pipes. My connection settings in CodeIgniter were:
Equivalent to:
I wrote up a custom page that just ran this sqlsrv_connect with the right config variables (username/password/UTF-8/etc). Then using
print_r( sqlsrv_errors());I was met with the following:Bizarre! But I now know that it’s something related to shared memory versus TCP/IP.
After digging through the documentation (chm file) for “Microsoft Drivers for PHP for SQL Server” I found that to connect via TCP/IP (on a local box) you need to use
(local), 1433as the servername – where 1433 is whatever port you’re using.To sum up the changes (CodeIgniter specific, but also generally for sqlsrv_connect). Changed /application/config/database.php:
to