Yii Framework Forum: Use sqlsrv with php 5.3.x and Yii - Yii Framework Forum

Jump to content

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

Use sqlsrv with php 5.3.x and Yii Rate Topic: -----

#1 User is offline   C0b0ll 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 05-April 11

Posted 05 April 2011 - 08:40 AM

Hello everybody,

My config :
  • OS : Windows XP
  • Php/Apache Srv : WAMP (php 5.3.0)


I try to connect my little project to a MsSql db. And then create my models.

1. I modified my config/main.php :
'db'=>array(
	'connectionString' => 'sqlsrv:host=myServer;port:1433;dbname=myDB',
	'emulatePrepare' => false,
	'username' => 'sa',
	'password' => '123456',
),


2. I have this error message :
CDbException
CDbConnection failed to open the DB connection: [08001][Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Connection string is not valid [87].


I'm sure that the server is accessible, this code is working :
$connectionInfo = array(
	'Database'=>$myDB,
	'UID'=>$myUser,
	'PWD'=>$myPass,
);
$dbhandle = sqlsrv_connect($myServer, $connectionInfo) 
	or die("Couldn't connect to SQL Server on $myServer : <br />".print_r(sqlsrv_errors(), true));

$query = sqlsrv_query($dbhandle, 'SELECT * FROM myTable');
while($obj = sqlsrv_fetch_object($query))
	echo $obj->name.'<br />';


I use the sqlsrv because the mssql is not longer supported by php 5.3.0. Is it possible to use sqlsrv with Yii ?
If yes, how ?


Thanks for your help.
0

#2 User is offline   Maurizio Domba Cerin 

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

Posted 06 April 2011 - 02:14 AM

I don't use this database... but as the error says "connection string is not valid"... I just googled "sqlsrv connection string" and got these two pages

http://www.connectio...sql-server-2008
http://www.connectio...sql-server-2005

So try to change your connection string... as on these examples there is no "host=" for the connection string
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   C0b0ll 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 05-April 11

Posted 06 April 2011 - 03:27 AM

Hello,

Tanks for your help.

Indeed, the connectionString contained mistakes. I changed to
'db'=>array(		
  'connectionString' => 'sqlsrv:Server=myServer;Database=myDB',
  'username' => 'sa',
  'password' => '123456',
  'emulatePrepare' => false,
  'charset' => 'utf8',
),


Now, I have this message :

Quote

CDbException

CDbConnection failed to open the DB connection: [08001][Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [53].

I'm sure that the server is accessible (see my fist post) with the command sqlsrv_connect().

What I'm doing wrong ? I must maybe change my PHP extensions... I'm using :
extension=php_sqlsrv_53_ts_vc6.dll
extension=php_pdo_sqlsrv_53_ts_vc6.dll


Yii is a very powerful framework and I want to use it for a European project. Unfortunately, the connection to a mssql server is needed.


Thanks,
0

#4 User is offline   Maurizio Domba Cerin 

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

Posted 06 April 2011 - 03:37 AM

Again... try to google for this kind of errors as they are not Yii related...

I just googled "Named Pipes Provider error 53" and here is a good explanation

http://social.msdn.m...a6-4cce10ecd7d3
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   C0b0ll 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 05-April 11

Posted 06 April 2011 - 04:38 AM

Hi,

It works ! :)

The problem came just from the version of the PHP extension php_pdo_sqlsrv_53_ts_vc6.dll. Now, I use the version 2.0.1802.200.

I downloaded the dlls here : www.microsoft.com/downloads/en/details.aspx?FamilyID=80e44913-24b4-4113-8807-caae6cf2ca05&displaylang=en

Many thanks for your help and sorry for my "non-related to Yii" question.


C0b0ll
0

Share this topic:


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

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

  1. dom.kkd