Yii Framework Forum: How to Connect mssql database - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

How to Connect mssql database Rate Topic: -----

#1 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 29 April 2011 - 04:23 AM

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 ??
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 29 April 2011 - 05:50 AM

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/m...f.pdo-dblib.php
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 02 May 2011 - 04:55 AM

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.
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 02 May 2011 - 05:03 AM

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...
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 02 May 2011 - 05:30 AM

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
0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 02 May 2011 - 05:35 AM

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...
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 02 May 2011 - 05:40 AM

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
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#8 User is offline   Cuong 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 17-April 11

Posted 03 May 2011 - 03:21 AM

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',
),
0

#9 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 03 May 2011 - 04:00 AM

View PostCuong, on 03 May 2011 - 03:21 AM, said:

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?
0

#10 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 03 May 2011 - 04:05 AM

View Postmdomba, on 02 May 2011 - 05:35 AM, said:

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?
0

#11 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 03 May 2011 - 04:07 AM

View Posttri, on 02 May 2011 - 05:40 AM, said:

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
0

#12 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 03 May 2011 - 04:12 AM

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...
Find more about me.... btw. Do you know your WAN IP?
0

#13 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 03 May 2011 - 04:15 AM

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

http://www.php.net/m...f.pdo-dblib.php

Quote

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: ยป http://msdn.microsof...r/ff657782.aspx .

If it is not possible to use SqlSrv, you can use the PDO_ODBC 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.


Find more about me.... btw. Do you know your WAN IP?
0

#14 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 03 May 2011 - 04:18 AM

View Postmdomba, on 03 May 2011 - 04:12 AM, said:

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?
0

#15 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 03 May 2011 - 04:23 AM

The description of this error is:

Quote

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...
Find more about me.... btw. Do you know your WAN IP?
0

#16 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 03 May 2011 - 04:35 AM

View Postmdomba, on 03 May 2011 - 04:23 AM, said:

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...index.php?r=gii

gii passwd = 1234
please be commented
0

#17 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 03 May 2011 - 05:23 AM

Seems that the reason for the error is the database driver... but for this you would need to check the server logs...
Find more about me.... btw. Do you know your WAN IP?
0

#18 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 05 May 2011 - 12:02 AM

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
0

#19 User is offline   donal 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-October 10

Posted 05 May 2011 - 05:05 AM

:D :D :D :D :D

PROBLEM SOLVED..!!!!! Yeah.....

thank's ALL
0

#20 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 05 May 2011 - 05:50 AM

Can you write what was the problem and how you solved it?
Find more about me.... btw. Do you know your WAN IP?
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users