开发者

Error using Cake PHP SQL Server Driver

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]
Query: SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES 

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] => pa开发者_开发问答ssword )

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?


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

http://www.microsoft.com/download/en/details.aspx?id=20098


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(192.168.1.13)
        '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
);
if(isset($config['ReturnDatesAsStrings'])){
         $connectionInfo['ReturnDatesAsStrings'] = $config['ReturnDatesAsStrings'];
}
$this->connection = sqlsrv_connect($config['host'] . $port, $connectionInfo);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜