MS-SQL DB Connection Driver

Hello,

I'm trying to establish a DB connection to a MS-SQL DB.

In my main.php I've defined the connection parameters :

'db_admin'=>array(

		'class'=>'CDbConnection',


		'connectionString'=>'mssql:host=XXX.XXX.XXX.XXX;port=1433;dbname=MyDBName',


		'username'=>'sa',


		'password'=>'MyPassWord'


	),

When I try to create execute a query I've got an error about the connection driver :

CDbException

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

The server's running under Debian Etch with php5.

I've installed the pdo php extension for odbc (php5-odbc) but it did not works.

I think I don't I've installed the good driver, but I don't know which one I should to installed.

Does anybody know which driver should be installed to establish connection to MS-SQL ??

Thanks

Swann

The  MySQL native driver for PHP works fine for me on FreeBSD. It should be also good solution for Debian, I suppose. Check this page for details.

Ed.

Hello,

Thanks for your answer :) but I think there is a misunderstanding ; I’m not trying to connect to a my-SQL DB but a MS-SQL DB. I’ve 3 connections on differents mySQL DB which work fine, this the MS-SQL connection which cause problem. ;)

Does anyone create a MSSQL connection under a Linux environnement ? which php(v5) driver should be used ?

Thanks

Swann

Hi,

to use ms-sql driver with PDO on linux You should instal dblib driver (pdo_dblib extension).

Yarro

Quote

[...]I'm not trying to connect to a my-SQL DB but a MS-SQL DB. [...]
Ups, you're right. MySQL is so popular, I haven't noticed it's MS SQL.

Quote

Hi,

to use ms-sql driver with PDO on linux You should instal dblib driver (pdo_dblib extension).

Yarro

well, and what else? which type of dbdriver should be written in db config? just 'mssql'? and what type of extension I need? I found the only 'mssql' extension, but it contains no items!

If you know solution of this, help, pls!

Hi,

Thanks all for your help : It works!

I've finally reinstall the pdo_dblib extension by an other way and now I can do some request on my remote host MS-SQL DB.

kvl : I do not completely understand your question, which dsn ? You can see i my first post in this topic the connectionString I've used to made it working.

Does your pdo dblib extension well loaded when you do phpinfo ? See section PDO, should be like it :

PDO drivers : dblib, mysql, odbc

And you should found a subsection pdo_dblib

Does it helps ?

Swann

Quote

kvl : I do not completely understand your question, which dsn ? You can see i my first post in this topic the connectionString I've used to made it working.

Does your pdo dblib extension well loaded when you do phpinfo ? See section PDO, should be like it :

PDO drivers : dblib, mysql, odbc

Sorry, I was unattentive when reading your first post.

I never used dblib and I work locally at WinXP, but I'll try it, thanks!

Hi,

typical dsn for dblib looks like:

$dsn = "'dblib:host=ms-sql_server_ip:port;dbname=example_db;','user_name','password'";

Swann, is your mssql connection able to read and write Unicode? I am using debian, Yii, and mssql. I am not able to read and write with Unicode characters. The query returns "?" where the Unicode characters are. The same happens when I try to save. If I switch to MySql, I am able to read and write Unicode with no problems. Do you have any ideas?

Thanks,