kingrichard2005
kingrichard2005

Reputation: 7269

PHP SQL Server driver not connecting

I'm using the Zend CE server with PHP 5.3.5 and Eclipse Helios with PDT to develop a database-driven PHP web application. I have my dev environment setup and enabled the SQL_Srv driver through the Zend control panel.

My problem is in my script when I call the sqlsrv_connect() function, it fails to connect to my SQL Server db and always returns false. I've verified I can connect to the server through a System DSN as well as Microsoft SQL Server Management Studio, so I know it's there and I can talk to it. These same settings also work on my coworker's dev environment (the same as mine), so I'm not sure what's missing. Has anyone else had similar issues with the PHP SQL Server driver? The relevant snippet of code:

$serverName = 'dbServer';
$connectionInfo = array ( "Encrypt" => 0, "LoginTimeout" => 10,  "Database" => "Test_DB", "UID" => "ABC", "PWD" => "123" );

//This is always false.  Does not connect
$test_Connect = sqlsrv_connect ( $serverName, $connectionInfo );

$GLOBALS['_connection'] = sqlsrv_connect ( $serverName, $connectionInfo );

if ( $GLOBALS['_connection'] == false ) {
    print_r ( sqlsrv_errors(), true );
    die ( "Failed to connect to SQL Server '$serverName'." );
}

Upvotes: 0

Views: 571

Answers (1)

kingrichard2005
kingrichard2005

Reputation: 7269

Turns out PHP SQLSrv driver requires the Microsoft SQL Server 2008 Native Client to function. Make sure it's the '08' client and not '05', I already had the native client for SQL Server 2005 installed while experiencing this issue. It was only after I installed the client for SQL Server 2008 that it worked properly. Hope this helps others.

Upvotes: 1

Related Questions