Problems connecting php5.5 to sql server with php_pdo_sqlsrv_55_ts.dll

Category: sql server driverphp


Alan Chandler on Mon, 02 Feb 2015 23:28:56

I am trying to retrieve code I last touched a couple of years ago to connect to a sql server database.  I have a little test utility to do that

<?php   $serverName = 'ROO\SQLEXPRESS';    $database = "PAS_Live";   // Get UID and PWD from application-specific files.   

$uid = "accu_app";   $pwd = "xxxxx";   try {      $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );    }   catch( PDOException $e ) { die( "Error connecting to SQL Server: $e" );    }   echo "Connected to SQL Server\n"; ?>

This used to work fine with the old version of the drivers.  Since time has moved on, I am trying this again with the latest drivers contained in the SQLSERVER31.EXE file that you can download.  In particular I have set up php5.5 to run with the extension file php_pdo_sqlsrv_55_ts.dll that that file contains.

Whe I run the little test program, it flags up this error (only partially listed it)

'SQLSTATE[IMSSP]: This extension requires the ODBC Driver 11 for SQL Server to communicate with SQL Server...'

I tried downloading the ODBC driver given in the link in the full message (which doesn't point to the driver - but you can find the download link from that link if you search for it), but it refused to install.  I presume that is because, according to my  Data Sources(ODBC)  (run from Administrative Tools), I already have a driver"Sql Server Native Client 11.0" installed.

What am I supposed to do to get this working.  There is absolutely no documentation with the driver that I can find to explain how this new driver works.  Does the connection string change for instance? Or can I uninstall an old client to install a new one.

I am currently doing all of this on Windows 7 Home Premium, but this is really just a test install for the long term plan to move it all to a Server 2011 installation.


Alan Chandler on Mon, 02 Feb 2015 23:37:36

Actually fixed it.  I was installing the wrong version of the ODBC driver.  It HAS to be the x64 version, despite everything else in PHP being in 32 bit mode.