WAMP + Yii + MSSQL == Driver not found

Hi there,

I’ve got a WAMP setup (work machine…) version 2.2 with PHP 5.3.13 with MSSQL and PDO_MSSQL loaded. I’ve looked at quite all the topics on this forum but could not resolve my problem:


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

I’ve tried different connectionStrings, none work, I ended up with:


'db' => array(

	    'connectionString' => 'mssql:host=127.0.0.1;dbname=Yiitest',

	    'username' => 'UltraPhil',

	    'password' => '...',

	    'charset' => 'utf8',

	    'emulatePrepare' => false,

	),




2012/08/13 19:53:51 [error] [exception.CDbException] exception 'CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in C:\wamp\www\yii-1.1.11.58da45\framework\db\CDbConnection.php:382

Stack trace:

#0 C:\wamp\www\yii-1.1.11.58da45\framework\db\CDbConnection.php(331): CDbConnection->open()

#1 C:\wamp\www\yii-1.1.11.58da45\framework\db\CDbConnection.php(309): CDbConnection->setActive(true)

#2 C:\wamp\www\yii-1.1.11.58da45\framework\base\CModule.php(388): CDbConnection->init()

#3 C:\wamp\www\yii-1.1.11.58da45\framework\base\CModule.php(104): CModule->getComponent('db')

#4 C:\wamp\www\yii-1.1.11.58da45\framework\gii\generators\model\ModelCode.php(56): CModule->__get('db')

#5 C:\wamp\www\yii-1.1.11.58da45\framework\web\CFormModel.php(40): ModelCode->init()

#6 C:\wamp\www\yii-1.1.11.58da45\framework\gii\CCodeGenerator.php(154): CFormModel->__construct()

#7 C:\wamp\www\yii-1.1.11.58da45\framework\gii\CCodeGenerator.php(64): CCodeGenerator->prepare()

#8 C:\wamp\www\yii-1.1.11.58da45\framework\web\actions\CInlineAction.php(50): CCodeGenerator->actionIndex()

#9 C:\wamp\www\yii-1.1.11.58da45\framework\web\CController.php(309): CInlineAction->runWithParams(Array)

#10 C:\wamp\www\yii-1.1.11.58da45\framework\web\CController.php(287): CController->runAction(Object(CInlineAction))

#11 C:\wamp\www\yii-1.1.11.58da45\framework\web\CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)

#12 C:\wamp\www\yii-1.1.11.58da45\framework\web\CWebApplication.php(283): CController->run('')

#13 C:\wamp\www\yii-1.1.11.58da45\framework\web\CWebApplication.php(142): CWebApplication->runController('gii/model')

#14 C:\wamp\www\yii-1.1.11.58da45\framework\base\CApplication.php(162): CWebApplication->processRequest()

#15 C:\wamp\www\yiitest\index.php(13): CApplication->run()

#16 {main}

REQUEST_URI=/yiitest/index.php/gii/model

HTTP_REFERER=localhost/yiitest/index.php/gii

As I said, I already read a lot of other threads, and I still can’t resolve this one.

Thanks!

i struggled a bit migrating mysql to mssql and finally made it work.

here is my setting, in php.ini (i could not make ;extension=php_mssql.dll work)


extension=php_sqlsrv_53_ts_vc9.dll

extension=php_pdo_sqlsrv_53_ts_vc9.dll



in protected/config/main.php


'db' => array(

            'connectionString' => 'sqlsrv:server=127.0.0.1;dbname=Yiitest',

            'username' => 'UltraPhil',

            'password' => '...',

        ),



there’re also some tune-ups need to be done, like

in mysql we use


limit 100

in mssql, we use


top 100

don’t ask me too much, that’s all i know. initially i thought yii would support any db in a neutral way, but actually not all DBs were created equal.

Alright!

Figured out.

  • Needed to install Wamp Server x86 ( had x64 ).

  • Downloaded SQLSRV30 from microsoft and added to php.ini:


extension=php_sqlsrv_53_ts.dll

extension=php_pdo_sqlsrv_53_ts.dll



  • Needed to comment out ‘emulatedPrepare’, true OR false would give me an error:

SQLSTATE[IMSSP]: The given attribute is only supported on the PDOStatement object.

Now it works.

Thanks !

(and I hope it helps someone someday).

Wow… thanks!!!

Just commented out emulatePrepare and it is working.

I’m on IIS 7.5, PHP 5.4.12 NTS and php_pdo_sqlsrv_54_nts.dll extension on Windows 2008 R2 + MS Sql Server 2005.

Wondering why both true/false values gives error?!

But the important thing is that now it works!

Thanks again,

Angelo

Maybe it’s because the default value of emulatePrepare is neither true nor false, it’s null:

http://www.yiiframework.com/doc/api/1.1/CDbConnection/#emulatePrepare-detail

The documentations says at the beginning that the default value is false, but later it says it’s null (maybe a mistake in the documentation).

It seems that a null value is treated differently for this attribute.