Yii & SQL Server

Hi all,

First time user of yii and I am planning to move an existing website over into the yii framework (along with a redesign).

The current site uses a SQL Server for the database so until we redesign the database (its used for multiple other things) we will have to stick to SQL Server (2005).

Anyway onto the Yii question, i’ve created a new Yii application and have that all working fine but i’m having trouble getting it to play nicely with the existing SQL Server database.

My DB setting is as follows:

'db' => array(

            'connectionString' => 'sqlsrv:server=(local);database=mydb',

            'emulatePrepare' => false,

            'username' => 'egg',

            'charset' => 'utf8',

            'password' => 'bacon',


And the error message I receive is

CDbConnection failed to open the DB connection: SQLSTATE[IMSSP]: An unsupported attribute was designated on the PDO object.

I have tested sqlsrv with the very same database on the same webserver outside of Yii and I have managed to get it working using this simple code:


   try {

      $conn = new PDO( "sqlsrv:server=(local);Database = mydb", 'egg', 'bacon'); 

      $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 


   catch( PDOException $e ) {

      die( "Error connecting to SQL Server" ); 


   echo "Connected to SQL Server\n";

   $query = 'select * from t_Dealers'; 

   $stmt = $conn->query( $query ); 

   while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){ 

      print_r( $row ); 



And it works fine, i get all the results i expect.

Any ideas why this isn’t working with Yii?

(I’m seeing this message when going to CRUD options in Gii)

I use MAM (MacOSx). In my configutation, my server must be localhost:8889. Need you something to this? To set the Mysql port?

Thanks for your help, but i’m using SQL Server (Microsoft) not MySQL. I don’t have a problem connecting to the server but once it connects there is an error.

I’m succesfully using MSSQL 2005 with this setting:


			'connectionString' => 'mssql:host=localhost;dbname=DB',

			'username' => 'user',

			'password' => 'password',



as far as I’ve understood, the “mssql” extension is older than “sqlsrv” one, but it works better.

HTH… bye!

I don’t currently have that extension installed, and as far i know it wouldn’t be a good idea to rely on an older extension.

I’m with you on that. But at least the legacy solutions work ;)


Since the error message complains about an unsupported attribute, I would try without the charset property.


I got this error too, I solve this problem removing the "emulatePrepare" attribute, like this:


                            'connectionString' => 'sqlsrv:server=localhost;database=Northwind;',

                            'username' => 'user',

                            'password' => 'user123',

                            'charset' => 'utf8',