Take the 2-minute tour ×

Upgraded a (dev) Cake PHP site and had to change database drivers from ADO to SQL Server's own driver as ADO is no longer supported in Cake 1.3, I . The new SQL Server driver is installed in PHP, shows in PHPinfo() and should work, but when I try to load a page using the database, I get this error:

Warning (2): sqlsrv_query() expects parameter 1 to be resource, boolean given 
[APP\plugins\datasources\models\datasources\dbo\dbo_sqlsrv.php, line 184]
Warning (512): SQL Error: An invalid parameter was passed to sqlsrv_query.
 [CORE\cake\libs\model\datasources\dbo_source.php, line 684]

What appears to be happening is my connection isn't established in the dbo_sqlsrv.php driver; a "$this->connection" variable is supposed to be the connection resource then passed to sqlsrv_query() and it's apparently a bool which is wrong (I tried to Echo the variable and it displays nothing).

This is where the connection SHOULD be set:

sqlsrv_connect($this->config['host'] . $port, $params)

Printing the variables that were passed in gives me this:

SRV, 1433 Array ( [Database] => DB [CharacterSet] => char 
[MultipleActiveResultSets] => [UID] => sa [PWD] => password )

Each of those parameters is correct, is there a specific way I should format or change my database configuration array for this driver or is there something I am missing?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

This error was due to outdated SQL Server drivers. Installing the latest from below allows a SQL Server connection:


share|improve this answer

I think there is some issue with your connection. PHP can't establish connection with sql Server.

var $default = array(
        'driver' => 'sqlsrv',
        'persistent' => false,
        'host' => 'Myhome-PC\SQLEXPRESS', // or ip-address(
        'login' => 'username',
        'password' => 'password',
        'database' => 'db',
        'prefix' => 'tbl',
        'port' => NULL,
        'returnDatesAsStrings' => True

I think the Connection should be this

Here is the sqlsrv_dbo which I used.

And your $param should be something like this

$connectionInfo = array("UID" => $config['login'], 
                        "PWD" => $config['password'], 
                        "Database" => $config['database'],   
                        'MultipleActiveResultSets' => 1,
                        'ConnectionPooling' => 0
         $connectionInfo['ReturnDatesAsStrings'] = $config['ReturnDatesAsStrings'];
$this->connection = sqlsrv_connect($config['host'] . $port, $connectionInfo);
share|improve this answer
That's exactly what it's doing though, I'm not configuring port info but it's using the default port which is right. your last block of code is almost exactly what's going on in the sqlsrv.php driver file. –  Ben Brocka Aug 3 '11 at 18:29
Have You tried to connect the sql server from simple php, I mean without framework? –  RSK Aug 3 '11 at 18:40
Can you please add some more code which you are using? –  RSK Aug 3 '11 at 18:47

Your Answer


