I’ve setup a database connection in my config file, and if I print out the contents of Yii::app() I can find the database connection details, and they are correct.
When trying to use the Gii model generator tool, however, it falls down on me.
53 public function init() {
54 echo '<pre>';
55 print_r(Yii::app()->db);
56 echo '</pre>';
57 die();
58 Yii::app()->db = array(
59 'connectionString' => 'sqlsrv:Server=sti-hq2k8; Database=TrulinXLive',
60 'username' => 'jzumbrum',
61 'password' => 'my_super_secret_password',
62 'charset' => 'utf8',
63 'tablePrefix' => 'tbl',
64 );
65 if(Yii::app()->db===null)
66 throw new CHttpException(500,'An active "db" connection is required to run this generator.');
Exception Message:
CDbConnection failed to open the DB connection: SQLSTATE[IMSSP]: The given attribute is only supported on the PDOStatement object.
Config settings:
'db'=>array(
'connectionString' => 'sqlsrv:Server=servername; Database=database',
'username' => 'jzumbrum',
'password' => 'password',
'charset' => 'GB2312',
'tablePrefix' => 'tbl',
)
From what I remember, I think I stopped having problems once I disabled emulating prepared statements:
Other possible problems/ fixes available here: http://www.yiiframework.com/forum/index.php/topic/17998-use-sqlsrv-with-php-53x-and-yii/