MSSQL connection

Hi

I have been trying to connect to a MSSQL database I have on my local Computer through Yii but I keep getting this error,


include(phppdo_sybase_statement.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory


C:\xampp\framework\YiiBase.php(418)

Which is making very little sense to me. The database is working because I connected with ASP.NET locally on my old website. All MSSQL things are running fine.

The steps I took so far are Downolading phppdo to fix the error I was getting previously. I also enabled TCP/IP on the Server Configuration but no luck. I searched Google and Yii Forums but ther’s very little info on this issue.

Does anyone please have a clue what’s wrong here?


'db'=>array(

      'class'=>'application.extensions.PHPPDO.CPdoDbConnection',

       'pdoClass' => 'PHPPDO',

      'connectionString' => 'mssql:Server=MYSRV\PAN; Database=mydb',

      'emulatePrepare' => false,

     'username' => 'AECSSA/place',

			'password' => '',

      'charset' => 'utf8',

    ),

This info above are correct and exactly the same I used to connect through ASP.NET. I’m guessing is more to do with installation because I’m not getting any syntax errors such as DB does not exist, etc.

Thanks All and Regards

Hi,

Still got no luck with this and I have been trying for a few days now. I’m really stuck here and any advice would be really appreciated. I I’m going to print my full error log to see if anyone can make sense of this.

PHP warning

include(phppdo_sybase_statement.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory


C:\xampp\framework\YiiBase.php(418)


406                 {

407                     foreach(self::$_includePaths as $path)

408                     {

409                         $classFile=$path.DIRECTORY_SEPARATOR.$className.'.php';

410                         if(is_file($classFile))

411                         {

412                             include($classFile);

413                             break;

414                         }

415                     }

416                 }

417                 else

418                     include($className.'.php');

419             }

420             else  // class name with namespace in PHP 5.3

421             {

422                 $namespace=str_replace('\\','.',ltrim($className,'\\'));

423                 if(($path=self::getPathOfAlias($namespace))!==false)

424                     include($path.'.php');

425                 else

426                     return false;

427             }

428             return class_exists($className,false) || interface_exists($className,false);

429         }

430         return true;

Stack Trace

#0	

+  C:\xampp\framework\YiiBase.php(418): YiiBase::autoload()

#1	

 unknown(0): YiiBase::autoload("phppdo_sybase_statement")

#2	

 unknown(0): spl_autoload_call("phppdo_sybase_statement")

#3	

–  C:\xampp\htdocs\panasonic\protected\extensions\PHPPDO\phppdo.php(354): class_exists("phppdo_sybase_statement")

349         }

350         

351         $driver_options[PDO::ATTR_DRIVER_NAME] = $this->driver_name;

352         

353         // load statement

354         if(!class_exists('phppdo_' . $driver . '_statement'))

355         {

356             $this->load('drivers/' . $driver . '_statement.php');

357         }

358         

359         if(!isset($driver_options[PDO::ATTR_STATEMENT_CLASS]))

#4	

–  C:\xampp\htdocs\panasonic\protected\extensions\PHPPDO\phppdo.php(56): PHPPDO->init_driver(array("server" => "MYSRV\PAN", "database" => "mydb"), "AECSSA/place", "", array(16 => "mssql"))

51         if($this->driver_name == 'uri')

52         {

53             $driver_dsn = $this->get_uri_dsn(key($driver_dsn));

54         }

55         

56         $this->init_driver($driver_dsn, $username, $password, $driver_options);

57     }

58     

59     public static function getAvailableDrivers()

60     {

61         if(func_num_args() > 0) return false;

#5	

–  C:\xampp\htdocs\panasonic\protected\extensions\PHPPDO\CPdoDbConnection.php(65): PHPPDO->__construct("mssql:Server=MYSRV\PAN; Database=mydb", "AECSSA/place", "", array())

60                 require_once('drivers/'.$driver.'_statement.php');

61             }

62 

63         }

64         return new $this->pdoClass($this->connectionString,$this->username,

65                                     $this->password,$this->_attributes);

66     }

67 }

68 

69 ?>

#6	

–  C:\xampp\framework\db\CDbConnection.php(374): CPdoDbConnection->createPdoInstance()

369             if(empty($this->connectionString))

370                 throw new CDbException(Yii::t('yii','CDbConnection.connectionString cannot be empty.'));

371             try

372             {

373                 Yii::trace('Opening DB connection','system.db.CDbConnection');

374                 $this->_pdo=$this->createPdoInstance();

375                 $this->initConnection($this->_pdo);

376                 $this->_active=true;

377             }

378             catch(PDOException $e)

379             {

#7	

–  C:\xampp\framework\db\CDbConnection.php(331): CDbConnection->open()

326     public function setActive($value)

327     {

328         if($value!=$this->_active)

329         {

330             if($value)

331                 $this->open();

332             else

333                 $this->close();

334         }

335     }

336 

#8	

–  C:\xampp\framework\db\CDbConnection.php(309): CDbConnection->setActive(true)

304      */

305     public function init()

306     {

307         parent::init();

308         if($this->autoConnect)

309             $this->setActive(true);

310     }

311 

312     /**

313      * Returns whether the DB connection is established.

314      * @return boolean whether the DB connection is established

#9	

–  C:\xampp\framework\base\CModule.php(388): CDbConnection->init()

383             if(!isset($config['enabled']) || $config['enabled'])

384             {

385                 Yii::trace("Loading \"$id\" application component",'system.CModule');

386                 unset($config['enabled']);

387                 $component=Yii::createComponent($config);

388                 $component->init();

389                 return $this->_components[$id]=$component;

390             }

391         }

392     }

393 

#10	

–  C:\xampp\framework\base\CModule.php(104): CModule->getComponent("db")

099      * @return mixed the named property value

100      */

101     public function __get($name)

102     {

103         if($this->hasComponent($name))

104             return $this->getComponent($name);

105         else

106             return parent::__get($name);

107     }

108 

109     /**

#11	

–  C:\xampp\htdocs\panasonic\protected\views\site\index.php(13): CModule->__get("db")

08 <ul>

09     <li>View file: <tt><?php echo __FILE__; ?></tt></li>

10     <li>Layout file: <tt><?php echo $this->getLayoutFile('main'); ?></tt></li>

11 </ul>

12 

13 <?php Yii::app()->db?>

14 

15 <p>For more details on how to further develop this application, please read

16 the <a href="http://www.yiiframework.com/doc/">documentation</a>.

17 Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,

18 should you have any questions.</p>

#12	

–  C:\xampp\framework\web\CBaseController.php(127): require("C:\xampp\htdocs\panasonic\protected\views\site\index.php")

122             $data=$_data_;

123         if($_return_)

124         {

125             ob_start();

126             ob_implicit_flush(false);

127             require($_viewFile_);

128             return ob_get_clean();

129         }

130         else

131             require($_viewFile_);

132     }

#13	

–  C:\xampp\framework\web\CBaseController.php(96): CBaseController->renderInternal("C:\xampp\htdocs\panasonic\protected\views\site\index.php", null, true)

091     {

092         $widgetCount=count($this->_widgetStack);

093         if(($renderer=Yii::app()->getViewRenderer())!==null && $renderer->fileExtension==='.'.CFileHelper::getExtension($viewFile))

094             $content=$renderer->renderFile($this,$viewFile,$data,$return);

095         else

096             $content=$this->renderInternal($viewFile,$data,$return);

097         if(count($this->_widgetStack)===$widgetCount)

098             return $content;

099         else

100         {

101             $widget=end($this->_widgetStack);

#14	

–  C:\xampp\framework\web\CController.php(870): CBaseController->renderFile("C:\xampp\htdocs\panasonic\protected\views\site\index.php", null, true)

865      */

866     public function renderPartial($view,$data=null,$return=false,$processOutput=false)

867     {

868         if(($viewFile=$this->getViewFile($view))!==false)

869         {

870             $output=$this->renderFile($viewFile,$data,true);

871             if($processOutput)

872                 $output=$this->processOutput($output);

873             if($return)

874                 return $output;

875             else

#15	

–  C:\xampp\framework\web\CController.php(783): CController->renderPartial("index", null, true)

778      */

779     public function render($view,$data=null,$return=false)

780     {

781         if($this->beforeRender($view))

782         {

783             $output=$this->renderPartial($view,$data,true);

784             if(($layoutFile=$this->getLayoutFile($this->layout))!==false)

785                 $output=$this->renderFile($layoutFile,array('content'=>$output),true);

786 

787             $this->afterRender($view,$output);

788 

#16	

–  C:\xampp\htdocs\panasonic\protected\controllers\SiteController.php(32): CController->render("index")

27      */

28     public function actionIndex()

29     {

30         // renders the view file 'protected/views/site/index.php'

31         // using the default layout 'protected/views/layouts/main.php'

32         $this->render('index');

33     }

34 

35     /**

36      * This is the action to handle external exceptions.

37      */

#17	

–  C:\xampp\framework\web\actions\CInlineAction.php(50): SiteController->actionIndex()

45         $controller=$this->getController();

46         $method=new ReflectionMethod($controller, $methodName);

47         if($method->getNumberOfParameters()>0)

48             return $this->runWithParamsInternal($controller, $method, $params);

49         else

50             return $controller->$methodName();

51     }

52 

53 }

#18	

–  C:\xampp\framework\web\CController.php(309): CInlineAction->runWithParams(array())

304     {

305         $priorAction=$this->_action;

306         $this->_action=$action;

307         if($this->beforeAction($action))

308         {

309             if($action->runWithParams($this->getActionParams())===false)

310                 $this->invalidActionParams($action);

311             else

312                 $this->afterAction($action);

313         }

314         $this->_action=$priorAction;

#19	

–  C:\xampp\framework\web\CController.php(287): CController->runAction(CInlineAction)

282      * @see runAction

283      */

284     public function runActionWithFilters($action,$filters)

285     {

286         if(empty($filters))

287             $this->runAction($action);

288         else

289         {

290             $priorAction=$this->_action;

291             $this->_action=$action;

292             CFilterChain::create($this,$action,$filters)->run();

#20	

–  C:\xampp\framework\web\CController.php(266): CController->runActionWithFilters(CInlineAction, array())

261         {

262             if(($parent=$this->getModule())===null)

263                 $parent=Yii::app();

264             if($parent->beforeControllerAction($this,$action))

265             {

266                 $this->runActionWithFilters($action,$this->filters());

267                 $parent->afterControllerAction($this,$action);

268             }

269         }

270         else

271             $this->missingAction($actionID);

#21	

–  C:\xampp\framework\web\CWebApplication.php(276): CController->run("")

271         {

272             list($controller,$actionID)=$ca;

273             $oldController=$this->_controller;

274             $this->_controller=$controller;

275             $controller->init();

276             $controller->run($actionID);

277             $this->_controller=$oldController;

278         }

279         else

280             throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',

281                 array('{route}'=>$route===''?$this->defaultController:$route)));

#22	

–  C:\xampp\framework\web\CWebApplication.php(135): CWebApplication->runController("")

130             foreach(array_splice($this->catchAllRequest,1) as $name=>$value)

131                 $_GET[$name]=$value;

132         }

133         else

134             $route=$this->getUrlManager()->parseUrl($this->getRequest());

135         $this->runController($route);

136     }

137 

138     /**

139      * Registers the core application components.

140      * This method overrides the parent implementation by registering additional core components.

#23	

–  C:\xampp\framework\base\CApplication.php(162): CWebApplication->processRequest()

157      */

158     public function run()

159     {

160         if($this->hasEventHandler('onBeginRequest'))

161             $this->onBeginRequest(new CEvent($this));

162         $this->processRequest();

163         if($this->hasEventHandler('onEndRequest'))

164             $this->onEndRequest(new CEvent($this));

165     }

166 

167     /**

#24	

–  C:\xampp\htdocs\panasonic\index.php(13): CApplication->run()

08 defined('YII_DEBUG') or define('YII_DEBUG',true);

09 // specify how many levels of call stack should be shown in each log message

10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

11 

12 require_once($yii);

13 Yii::createWebApplication($config)->run();

14 

2012-05-26 09:36:26 Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1 Yii Framework/1.1.9



If someone has connected to MSSQL before on their local PC Via Xampp & Yii please tell me all the steps you followed. I tried all tutorials and forum advice I can find but not many have come across my issue which can only mean I done something wrong. Only problem is I have no clue what it can be.

Regards & Thanks

Hi. I’ve no experience with MSSQL + Yii, but have you seen this post: Yii & SQL Server? It’s not the error you describe but it seems they found a working db connection parameter set.

Also there has is this wiki that has been recently updated: Use MS SQL SERVER 2005 2008. It gives a different syntax.

Fyi, both do not have emulatePrepare parameter.

After Hours of trying to figure this out I would like to thank bennouna for guiding me. I finally managed to connect but it seems a tad unarthodox the way I done it. Anyway for anyone that wants to know here it goes.

First of all I didn’t use the PDO extension, apparently mssql method is legacy and no longer recommended. I had to first downolad the drivers to use sqlsrv from the Microsoft site from the link. Here, Download Driver .

I used SQLSRV30.EXE because I have SQL SERVER 2008 R2, you decide which you one you need according to your Server. Actually I tried both download links and that one worked for me. Follow the instructions and it’s pretty straight forward mind you, you must have access to your php.ini (I’m using local so it’s always available, some providers restrict access).

After installing the Driver I received another error- Can’t remember what but something to do with updating my SQL SERVER ODBC Driver using Native Client, pretty straight forward and the error provides the link. Microsoft® SQL Server® 2012 Native Client.

The last error I got was something to do with Name Pipes which took me hours to figure out and I still didn’t actually. I tried setting premission for the User, enabling Name Pipes and TCP/IP for my Database but the error presisted. Finally this morning I came across this link. It shows you how to connect SQL Server via PHP and I noticed they didn’t include username and password. So that’s what I done I omitted everything and my connection string was…





'db'=>array(

		 

'connectionString' => 'sqlsrv:MYSRV\PAN; Database=mydb;',

                            

  ),



That’s what worked for me but for now I’m just going to make some models, controllers, etc and leave the password battle for another time.

Again thanks bennouna for doing some research for me, exactly what I needed.

I just had the same troubles as you.

The solution should be mentioned on the DB connection page: NOLINKALLOWED://www.yiiframework.com/doc/guide/1.1/en/database.dao

(I can’t even leave any comment there yet…)

My solution was to download the PDP sqlsrv drivers AND the Microsoft SQL Server Native Client from this Microsoft page:

NOLINKALLOWED://msdn.microsoft.com/en-us/library/cc296170.aspx

Then I’ve put the appropriate driver (see SQLSRV_Readme.htm) into the directory …\PHP\ext\ and activated them by inserting the following lines into php.ini:


extension=php_sqlsrv_53_ts_vc9.dll

extension=php_pdo_sqlsrv_53_ts_vc9.dll

(change the dll names as needed!)


		'db'=>array(

			'connectionString' => 'sqlsrv:server=MY_SERVERNAME;Database=MY_DATABASENAME;',

			'username' => 'MY_USERNAME',

			'password' => 'MY_PASSWORD',

		),

I am no luck with this. I already use the .dll appropriate for my php version and tried connect and an error say "CDbConnection failed to open the DB connection: could not find driver"

I tried connecting in native form and it was successful, it means I applied the correct .dll for my php.