Yii Framework Forum: Connect To Mssql - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Connect To Mssql Rate Topic: ***** 1 Votes

#1 User is offline   dev-pro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 29-December 13

Posted 30 December 2013 - 01:30 AM

Hi I have problem with connection.
This code works fine for me
C:/xampp/htdocs/someProject/index.php
$server = "122.212.161.80";	
$link = mssql_connect($server, 'sa', 'xxx');
if (!$link) {
  die('Something went wrong while connecting to MSSQL');
}
else
{
  mssql_select_db("ALC", $link);
  // query or anyhting
}


but in Yii it is not working
here is my main.php
'db'=>array(
	'connectionString' => 'mssql:server=122.212.161.80;database=ALC',
	'emulatePrepare' => false,
	'username' => 'sa',
	'password' => 'xxx',
	'charset' => 'utf8',
),


SomeController.php
$cmd = Yii::app()->db->createCommand();
$cmd->select = 'Count(*)';
$cmd->from = 'base';        
$num = $cmd->queryScalar();
$this->render('index', array('data'=>$num));


here is an error

Quote

CDbConnection failed to open the DB connection: SQLSTATE[28000] Login incorrect. (severity 2)



can anyone help me please?
thanks
0

#2 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 507
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 30 December 2013 - 07:05 AM

I believe that "mssql" driver is problematic. I use the newer Microsoft Drivers 3.0 for PHP for SQL Server and connect successfully like so:

'db'=>array(
    'connectionString' => 'sqlsrv:server=localhost\\sqlexpress;database=MYDB',
    'username'=>'sa',
    'password'=>'xxx',
    'nullConversion' => PDO::NULL_EMPTY_STRING,
),


Notice it uses the "sqlsrv" driver and also makes reference to the instance. YMMV...
José
0

#3 User is offline   dev-pro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 29-December 13

Posted 30 December 2013 - 07:28 AM

At the time I am workin on Windows 7
Xampp version: 1.7.0
PHP: 5.2.8
but I have installed Windows Server 2008 R2 to another PC
Xampp version: 1.7.0
PHP: 5.2.8
and this works!!!

I think the problem is that I have php_pdo_mssql.dll extension is not right version for Windows 7. And I couldn't find. Because this code give me same error. It is simple php code.
try
{			
	$conn = new PDO("mssql:dbname=ALC;server=122.212.161.80", 'sa', 'xxx');
	$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(Exception $e)
{ 
	die( print_r( $e->getMessage() ) ); 
}


Same error

Quote

SQLSTATE[28000] Login incorrect. (severity 2)1

0

#4 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 507
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 30 December 2013 - 08:14 AM

What does <?php phpinfo(); ?> say about the PDO drivers?
José
0

#5 User is offline   dev-pro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 29-December 13

Posted 30 December 2013 - 08:33 AM

Quote

Installed PDO Drivers --- mssql, mysql, sqlite2

php_pdo_mysql works fine!!!

Do you have link that I can download php_pdo_mssql.dll which matches my requirments?
0

#6 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 507
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 30 December 2013 - 10:08 AM

If phpinfo() says "Installed PDO Drivers --- mssql, mysql, sqlite2" and you don't have the .dll it probably means that it was compiled into the PHP executable. The link I provided above *may* have what you need in version 2.0 but since your PHP is so old it may no longer be supported.

I normally don't use XAMPP but rather use the Windows native tools directly so I can't help you much there; perhaps upgrading to a newer XAMPP will solve your problem.
José
0

#7 User is offline   aravintharaj 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 15-July 14

Posted 15 July 2014 - 09:47 AM

Hi,

I am trying to connect MS SQL server in my YII project.

i have done the modifications in main.php file as like below, also i have installed SQL srv PHP extension(php_sqlsrv_53_ts_vc9) in my WAMP stack.

'connectionString' => 'sqlsrv:Server=hostname;Database=db_name',
'emulatePrepare' => false,
'username' => 'user_name',
'password' => 'password',
'charset' => 'utf8'

i am getting the below error message:

CDbException

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

Kindly help me to resolve the issue
0

#8 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 507
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 15 July 2014 - 11:48 AM

What does <?php phpinfo(); ?> or the Yii requirements checker page say about the PDO drivers? Are they installed?

The other thing you might be missing is the DB instance on the connection string, as in 'connectionString'=>'sqlsrv:server=hostname\SQLEXPRESS;database=db_name'.
José
0

Share this topic:


Page 1 of 1
  • 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