How to Connect mssql database

Hello Yii’er I have a problem with the connection ms sql server database.

this is my code



			'connectionString' => 'mssql:host=ELEKTRASRV;dbname=ELEKTRA3',

			//'emulatePrepare' => true,

			'username' => 'sa',

			'password' => '123456',

			//'charset' => 'utf8',


and this error comes out

CDbConnection failed to open the DB connection: could not find driver

anyone can help me get drivers to connect to sql server?

or any solution ??

Yii uses PHP PDO drivers to connect to different databases -

For MSSQL check this documentation -

sorry, I’m still confused, there are already successfully connects Yii with ms sql? can share code?

I’ve tried to upload to the server, but still could not connect.

please help me.

I’m not using MSSQL…

But as I wrote above… for Yii to connect to MSSQL you need the specific PDO driver to be installed…

so first thing is to check if you have that installed…

if you check the drivers on the localhost I can (do not already installed). but how do I check the drivers on the server? (because I’ve uploaded to the server)

sorry I was a newbie

You can check the result of the phpinfo() function, there should be the PDO paragraph with the list of PDO drivers installed…

… or simply ask the tech support to install it for you if it’s not already installed…

Connecting to SQL Server from linux or windows?

Besides the links mdomba posted, also check if you can find any useful information from google (e.g. " mssql")


Looks like you have a typo at mssql:host for mysql:host

Make sure you set the mysql port if you have any. Here’s what I got, hopefully it helps.


		'connectionString' => 'mysql:host=localhost;mysql:port=xxxx;dbname=xxxxx',

		'emulatePrepare' => true,

		'username' => 'username',

		'password' => 'password',

		'charset' => 'utf8',


I am sure I am not a typo, because I really want to connect to MSSQL. can help me to connect to MSSQL?

I’ve contact cs hosting to convince the drivers are installed, but with the following code as yet can not connect as well.


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

		'emulatePrepare' => false,

		'username' => 'XXXX',

		'password' => 'XXXX',

		//'charset' => 'utf8',


have a solution?

i’am connect to windows hosting

If you are getting always the same error "could not find driver"

The problem is still the same… you don’t have the PDO driver for MSSQL… could be that they are not installed or maybe they are installed but not enabled…

Check the output of phpinfo() to be sure…

As you are on windows hosting… have you checked the documentation link I gave you in above post

I found an error in the server

500 - Internal server error.

whether my syntax is correct?

The description of this error is:

So it can be anything… from a directive in .htaccess to some code of yours…

You would need to check the server logs… or if you can’t do that… I would suggest to create a new yii webapp just to see if it works on the server… then add the database connection and again see if it work…

sorry maybe I was less clear in explaining.

like this

please check (Yii is already running)

but when I would use the command crud in gii

please try

gii passwd = 1234

please be commented

Seems that the reason for the error is the database driver… but for this you would need to check the server logs…

I still get an error like this:

CDbConnection failed to open the DB connection: could not find driver

on the server already installed drivers php_mssql and php_pdo_mssql

this my code :


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

	'emulatePrepare' => false,

	'username' => 'XXXX',

	'password' => 'XXXXX',

	'charset' => 'utf8',



I also have tried using


	'connectionString' => 'dblib:host=localhost;dbname=elektra7',

	'emulatePrepare' => false,

	'username' => 'XXXX',

	'password' => 'XXXXX',

	'charset' => 'utf8',



have a solution ?, because this is very important to me

:D :D :D :D :D


thank’s ALL

Can you write what was the problem and how you solved it?