我有SQL Server Express 2012 sp2在Windows 10, PHP版本5.5.28,Yii版本1.1.16,SQL Native Client 11安装
我已按照以下链接
中的说明操作为SQL Server Express 2012启用远程连接
但是下面的代码可以工作
<?php
$serverName = "localhost\sqlexpress"; //serverNameinstanceName
$connectionInfo = array( "Database"=>"ZDP", "UID"=>"sa", "PWD"=>"sa123123");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
但是Yii中的下列连接设置不起作用
'db'=>array(
'connectionString' => 'sqlsrv:Server=localhost\SQLEXPRESS; Database=ZDP',
'username' => 'sa',
'password' => 'sa123123',
),
并给出以下错误
CDbConnection failed to open DB connection: SQLSTATE[28000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'sa'.日志含义
还请注意,应用程序是使用YII版本1.1.13创建的,但现在我将其转移到新系统
对于感兴趣的人来说,下面的字符串可以工作:
'connectionString' => 'sqlsrv:Server=localhost; Database=ZDP',
为我工作:
'db'=>array(
'connectionString' => 'sqlsrv:server=localhost;database=mydatabase;',
'username' => 'myusername',
'password' => 'mypassword',
'charset' => 'utf8',
),