Cdbconnection Failed To Open Db Connection : Could Not Find Driver

Following is the complete error output…





CDbException


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


/var/www/eesystem/protected/components/Controller.php(23)


11      */

12     public $layout='//layouts/column1';

13     /**

14      * @var array context menu items. This property will be assigned to {@link CMenu::items}.

15      */

16     public $menu=array();

17     /**

18      * @var array the breadcrumbs of the current page. The value of this property will

19      * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}

20      * for more details on how to specify this property.

21      */

22         public function init() {

23             if(Yii::app()->user->isGuest) {

24                 echo "JJJ";

25                 //Yii::app()->user->loginRequired();

26             }

27         }

28     public $breadcrumbs=array();

29 }


Stack Trace

#0 	

+

 /var/www/yii-1.1.13/framework/db/CDbConnection.php(330): CDbConnection->open()

#1 	

+

 /var/www/yii-1.1.13/framework/web/CDbHttpSession.php(185): CDbConnection->setActive(true)

#2 	

 unknown(0): CDbHttpSession->openSession("/var/lib/php5", "PHPSESSID")

#3 	

+

 /var/www/yii-1.1.13/framework/web/CHttpSession.php(118): session_start()

#4 	

+

 /var/www/yii-1.1.13/framework/web/CHttpSession.php(92): CHttpSession->open()

#5 	

+

 /var/www/yii-1.1.13/framework/base/CModule.php(387): CHttpSession->init()

#6 	

+

 /var/www/yii-1.1.13/framework/web/CWebApplication.php(201): CModule->getComponent("session")

#7 	

+

 /var/www/yii-1.1.13/framework/web/auth/CWebUser.php(193): CWebApplication->getSession()

#8 	

+

 /var/www/yii-1.1.13/framework/base/CModule.php(387): CWebUser->init()

#9 	

+

 /var/www/yii-1.1.13/framework/base/CModule.php(103): CModule->getComponent("user")

#10 	

–

 /var/www/eesystem/protected/components/Controller.php(23): CModule->__get("user")


18      * @var array the breadcrumbs of the current page. The value of this property will

19      * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}

20      * for more details on how to specify this property.

21      */

22         public function init() {

23             if(Yii::app()->user->isGuest) {

24                 echo "JJJ";

25                 //Yii::app()->user->loginRequired();

26             }

27         }

28     public $breadcrumbs=array();


#11 	

+

 /var/www/yii-1.1.13/framework/web/CWebApplication.php(281): Controller->init()

#12 	

+

 /var/www/yii-1.1.13/framework/web/CWebApplication.php(141): CWebApplication->runController("")

#13 	

+

 /var/www/yii-1.1.13/framework/base/CApplication.php(169): CWebApplication->processRequest()

#14 	

–

 /var/www/eesystem/index.php(25): CApplication->run()


20 require_once($helpers);

21 require_once($pdfhelpers);

22 //require_once($firephp1);

23 //require_once($firephp2);

24 

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


2013-06-28 23:33:59 Apache/2.2.22 (Ubuntu) Yii Framework/1.1.13




Please help.

Hi

Can u post your code config/main.php

Double check your connection string. It could be you have mistyped.

Connection String should be like this:




...

// FOR MySQL

'connectionString' => 'mysql:host=127.0.0.1;port=3306;dbname=mydatabase;'

// FOR PgSQL

'connectionString' => 'pgsql:host=127.0.0.1;port=5432;dbname=mydatabase;'

// FOR SQLite

'connectionString' => 'sqlite:path/to/dbfile...'



But same code is working on XAMPP (windows). While published on LAMP (Ubuntu), problem started appearing.

Just a doubt, is there anything to do with PHP SESSION?

Install mysql driver on server, or provide the path of existing driver to system path.

mysql is already installed on server, but i don’t know how to give path to the driver.

Hi

please remove the colon after Db name


'connectionString' => 'mysql:host=127.0.0.1;port=3306;dbname=mydatabase'

somrhthing lookl like this




$configArray['components']['db'] = array(

        'connectionString' => 'mysql:host=127.0.0.1;dbname=test',


        'emulatePrepare' => true,

        'username' => 'other',

        'password' => 'password',

        'charset' => 'utf8',

);

Please see the config file main.php below. There is no extra colon in dbstring.




<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.


//require_once(dirname(_FILE_) . '/../components/helpers.php');

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

        /*'behaviors'=>array(

            'onBeginRequest'=>array(

                'class'=>'application.components.RequireLogin',

            ),

        ),*/

	'name'=>'Electrical Maintenance',


	// preloading components

	'preload'=>array(

            'log',

            //'bootstrap',

            ),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

                'application.modules.user.models.*',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool

		

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'samrat',

		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

                        /*'generatorPaths'=>array(

                            'bootstrap.gii',                            

                        ),*/

		),

                'eeconfig',

                'user' => array(

                    'debug' => false,

                    'userTable' => 'user',

                    'translationTable' => 'translation',

                ),

                'usergroup' => array(

                    'usergroupTable' => 'user_group',

                    'usergroupMessagesTable' => 'user_group_message',

                ),

                'membership' => array(

                    'membershipTable' => 'membership',

                    'paymentTable' => 'payment',

                ),

                'friendship' => array(

                    'friendshipTable' => 'friendship',

                ),

                'profile' => array(

                    'privacySettingTable' => 'privacysetting',

                    'profileFieldTable' => 'profile_field',

                    'profileTable' => 'profile',

                    'profileCommentTable' => 'profile_comment',

                    'profileVisitTable' => 'profile_visit',

                ),

                'role' => array(

                    'roleTable' => 'role',

                    'userRoleTable' => 'user_role',

                    'actionTable' => 'action',

                    'permissionTable' => 'permission',

                ),

                'message' => array(

                    'messageTable' => 'message',

                ),		

	),


	// application components

	'components'=>array(

		'user'=>array(

                    'class'=>'application.modules.user.components.YumWebUser',

                    // enable cookie-based authentication

                    'allowAutoLogin'=>true,

                    'loginUrl'=>array('//user/user/login'),

		),

                'cache'=>array(

                    'class'=>'CApcCache',                    

                ),

		// uncomment the following to enable URLs in path-format

		/*

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		*/

		/*'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),*/

		// uncomment the following to use a MySQL database

		'db'=>array(

			'connectionString' => 'mysql:host=192.168.55.1;dbname=eesystem',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => 'xxxxxx',

			'charset' => 'utf8',

                        'tablePrefix'=>'',

		),

		

		'errorHandler'=>array(

                    // use 'site/error' action to display errors

                    'errorAction'=>'site/error',

                ),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

                                    'class'=>'CFileLogRoute',

                                    'levels'=>'error, warning',

				),

                                /*array(

                                    'class'=>'CWebLogRoute',

                                    'categories'=>'system.db.CDbCommand',

                                    'showInFireBug'=>true,

                                ),*/

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

                'session'=>array(

                    'class'=>'CDbHttpSession',

                    'timeout'=>900,

                ),

                /*'bootstrap'=>array(

                    'class'=>'ext.bootstrap.components.Bootstrap',  

                    'coreCss'=>false,

                ),*/

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'webmaster@example.com',

	),

        'theme'=>'sk_theme1',

);



run phpinfo() and check what pdo_* extensions are installed. if there is no pdo_mysql - you must install it or enable in php.ini config file.

Checked phpinfo() pdo_mysql is already installed.

Kindly remove this line, it will work fine.




'session'=>array(

                    'class'=>'CDbHttpSession',

                    'timeout'=>900,

                ),