Use sqlsrv with php 5.3.x and Yii

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

),

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

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.connectionstrings.com/sql-server-2008

http://www.connectionstrings.com/sql-server-2005

So try to change your connection string… as on these examples there is no "host=" for the connection string

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 :

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,

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.microsoft.com/forums/en-US/sqldataaccess/thread/f398623b-d32b-4bf9-b2a6-4cce10ecd7d3

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

this file:

php_sqlsrv_54_ts.dll, php_pdo_sqlsrv_54_ts.dll

It will running on linux?

I am using

centos 6.5


ms sql 2000


php 5.6.0RC4


and installed [size=&quot;2&quot;]php-mssql.[/size]

[size="2"]But I still cannot connect to mssql. My config as below[/size]

[size="2"]





		'db'=>array(

    			'connectionString' => 'mssql:host=192.168.0.3;dbname=eBooking',

                        'username' => 'sa',

    			'password' => '123456',

                        'emulatePrepare' =>false

		)



[/size]

[size="2"]I want to create model using gii and error display as below. Please help[/size]

[size="2"]




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


/var/www/html/yii-1.1.14.f0fee9/framework/gii/generators/model/ModelCode.php(60)


public function init()

{

 	if(Yii::app()->{$this->connectionId}===null)

        throw new CHttpException(500,'A valid database connection is required to run this generator.');

    $this->tablePrefix=Yii::app()->{$this->connectionId}->tablePrefix;

    parent::init();

}



[/size]

Hello

Im having a big problem trying to connect YYI whtich MS SQL EXPRESS 2005

im using XAMP server,on a VM with WServer 2003 R2 32 bit

with PHP 5.4.31

y donwload and install

php_pdo_sqlsrv_54_ts.dll

php_sqlsrv_54_ts.dll

also de MS SQL Native client 2005

and y try connecting with this script

<?php

$serverName = "200.xxx.xxx.xxx.\sqlexpress"; //serverName\instanceName

$connectionInfo = array( "Database"=>"test4", "UID"=>"test", "PWD"=>"test");

$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {

 echo &quot;Conexión establecida.&lt;br /&gt;&quot;;

}else{

 echo &quot;Conexión no se pudo establecer.&lt;br /&gt;&quot;;


 die( print_r( sqlsrv_errors(), true));

}

?>

It work fine

but when i try YII

it didnt connect,

my web page freeze and never stop

i’m using this connection script

‘db’=>array(

  'connectionString' =&gt; 'sqlsrv:Server=200.xxx.xxx.xxx.;Database=test4',


      'username' =&gt; 'test',


      'password' =&gt; 'test',


      'emulatePrepare' =&gt; false,


      'charset' =&gt; 'utf8',


	


	),

what is wrong???

Can you download latest version of the SQL driver? Such as below or even more latest? thx.

extension=php_sqlsrv_55_ts.dll

extension=php_pdo_sqlsrv_55_ts.dll

Hi, anyone can help me? I have this problem:

CDbCommand falló al ejecutar la sentencia SQL: SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘pbis_meta.pbi_security_user’ doesn’t exist. The SQL statement executed was: SELECT * FROM pbis_meta.PBI_SECURITY_USER

what’s happend?

How can I know if the connectionString is wrong or not?

Thanks

J.