donal
(Donal Fw)
April 29, 2011, 9:23am
1
Hello Yii’er I have a problem with the connection ms sql server database.
this is my code
main.php
'db'=>array(
'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 ??
mdomba
(Maurizio Domba Cerin)
April 29, 2011, 10:50am
2
Yii uses PHP PDO drivers to connect to different databases - http://php.net/manual/en/book.pdo.php
For MSSQL check this documentation - http://www.php.net/manual/en/ref.pdo-dblib.php
donal
(Donal Fw)
May 2, 2011, 9:55am
3
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.
mdomba
(Maurizio Domba Cerin)
May 2, 2011, 10:03am
4
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…
donal
(Donal Fw)
May 2, 2011, 10:30am
5
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
mdomba
(Maurizio Domba Cerin)
May 2, 2011, 10:35am
6
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…
tri
(tri - Tommy Riboe)
May 2, 2011, 10:40am
7
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. "site:yiiframework.com mssql")
/Tommy
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.
'db'=>array(
'connectionString' => 'mysql:host=localhost;mysql:port=xxxx;dbname=xxxxx',
'emulatePrepare' => true,
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
),
donal
(Donal Fw)
May 3, 2011, 9:00am
9
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.
'db'=>array(
'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?
donal
(Donal Fw)
May 3, 2011, 9:05am
10
mdomba:
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…
I’ve contact cs hosting to convince the drivers are installed, but with the following code as yet can not connect as well.
'db'=>array(
'connectionString' =>'mssql:host=localhost;dbname=elektra7',
'emulatePrepare' => false,
'username' => 'XXXX',
'password' => 'XXXX',
//'charset' => 'utf8',
),
have a solution?
donal
(Donal Fw)
May 3, 2011, 9:07am
11
tri:
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. "site:yiiframework.com mssql")
/Tommy
i’am connect to windows hosting
mdomba
(Maurizio Domba Cerin)
May 3, 2011, 9:12am
12
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…
mdomba
(Maurizio Domba Cerin)
May 3, 2011, 9:15am
13
As you are on windows hosting… have you checked the documentation link I gave you in above post
http://www.php.net/manual/en/ref.pdo-dblib.php
This extension is not available anymore on Windows with PHP 5.3 or later.
On Windows, you should use SqlSrv, an alternative driver for MS SQL is available from Microsoft: [url="http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx"]» http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx [/url].
If it is not possible to use SqlSrv, you can use the [url="http://www.php.net/manual/en/ref.pdo-odbc.php"]PDO_ODBC[/url] driver to connect to Microsoft SQL Server and Sybase databases, as the native Windows DB-LIB is ancient, thread un-safe and no longer supported by Microsoft.
donal
(Donal Fw)
May 3, 2011, 9:18am
14
mdomba:
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…
I found an error in the server
500 - Internal server error.
whether my syntax is correct?
mdomba
(Maurizio Domba Cerin)
May 3, 2011, 9:23am
15
The description of this error is:
This is a ‘catch-all’ error generated by the Web server. Basically something has gone wrong, but the server can not be more specific about the error condition in its response to the client. In addition to the 500 error notified back to the client, the Web server should generate some kind of internal error log which gives more details of what went wrong. It is up to the operators of the Web server site to locate and analyse these logs.
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…
donal
(Donal Fw)
May 3, 2011, 9:35am
16
mdomba:
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 http://tes.smsberita.com/index.php (Yii is already running)
but when I would use the command crud in gii
please try http://tes.smsberita.com/index.php?r=gii
gii passwd = 1234
please be commented
mdomba
(Maurizio Domba Cerin)
May 3, 2011, 10:23am
17
Seems that the reason for the error is the database driver… but for this you would need to check the server logs…
donal
(Donal Fw)
May 5, 2011, 5:02am
18
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 :
'db'=>array(
'connectionString' => 'mssql:host=localhost;dbname=elektra7',
'emulatePrepare' => false,
'username' => 'XXXX',
'password' => 'XXXXX',
'charset' => 'utf8',
),
I also have tried using
'db'=>array(
'connectionString' => 'dblib:host=localhost;dbname=elektra7',
'emulatePrepare' => false,
'username' => 'XXXX',
'password' => 'XXXXX',
'charset' => 'utf8',
),
have a solution ?, because this is very important to me
mdomba
(Maurizio Domba Cerin)
May 5, 2011, 10:50am
20
Can you write what was the problem and how you solved it?