简体   繁体   中英

Cannot connect Yii with local SQL Server 2012

I have SQL Server Express 2012 sp2 on Windows 10, PHP Version 5.5.28, Yii Version 1.1.16, Sql Native Client 11 installed

I have followed the instructions in the following link

Enable remote connections for SQL Server Express 2012

but the following code works

<?php
$serverName = "localhost\\sqlexpress"; //serverName\instanceName
$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));
}
?>

but the following connection setting in Yii does not work

    'db'=>array(
        'connectionString' => 'sqlsrv:Server=localhost\\SQLEXPRESS; Database=ZDP',
        'username' => 'sa',
        'password' => 'sa123123',
    ),

and gives the following error

CDbConnection failed to open the DB connection: SQLSTATE[28000]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'sa'.

Also note that the application was created using YII Version 1.1.13 but now i am transferring it to new system

对于任何感兴趣的人,以下字符串工作:

'connectionString' => 'sqlsrv:Server=localhost; Database=ZDP',

Worked for me:

'db'=>array(
    'connectionString' => 'sqlsrv:server=localhost;database=mydatabase;',
    'username' => 'myusername',
    'password' => 'mypassword',
    'charset' => 'utf8',
    ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM