while trying to connect with mysql in yii framework it shows

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

my php drivers are already enabled , but it shows the same error

Im using zend studio, zend server for this

how could i fix this?

8 Answers 8

I am using Linux Mint..In my case I needed

because I was moving my environment from Lampp to Apache + PHP + MySQL and I had to change a lot of things in the php.ini

Things you should check

First you should check phpinfo() for the pdo_drivers installed.

if u use IIS server , you should check php extensions installed or not.

check php.ini for extensions_dir is properly given

check you ext folder in php contains pdo_mysql dlls

Some times the problem may occur due to zend server installation .You should check zend server is properly using the php extensions

After that check simple php-mysql connection using the following functions

If it works then go with Yii, Slim, Zend php-mysql connections

Суть в том,что на локальном сервере у меня все хорошо работало,ошибки такой не было. Когда я залил на хостинг,то начала вылезать ошибка CDbConnection failed to open the DB connection. Уже 2 дня мучаюсь. Даже пробывал на другой хостинг залить,все тчетно. С соединением все норм, на локальном сервере у меня все отлично работало.Даже и не заню,что делать. PHP версия 7.1. Пробывал даже с 5.4

Comments

Copy link Quote reply

bamburillo commented May 26, 2013

First of all, thanks for your great template which help a lot.

I met some error so reproduce step are:

  1. run command "php composer.phar self-update"
  2. run command "php composer.phar install"
    And after all this, I got this:

D:OpenServerdomainsasic>php composer.phar install

  • download packages specified in composer.json
  • configures your runtime folders
  • triggers composer callbacks (yiic commands)

Start Installation? [y/n]: y
Loading composer repositories with package information
Installing dependencies

  • Installing yiisoft/yii (1.1.13)
    Loading from cache

Please, enter your environment -ie. "dev | prod | stage": [dev]: dev

Building environment files.
Your environment configuration file has been created on D:OpenServerdomainsasicapplibYiinitializrconfig/../../../config
.

‘D:OpenServerdomainsasicapplibYiinitializrconfig/../../../config/env.php’
file already exists. No action has been executed.
‘D:OpenServerdomainsasicapplibYiinitializrconfig/../../../config/env.php’
file already exists. No action has been executed.
Environment files creation process finished.

Building runtime ‘runtime’ folders.
Your runtime folder has been created on D:OpenServerdomainsasicapplibYiinitializrconfig/../../.
Runtime ‘runtime’ folders creation process finished.

Building runtime ‘assets’ folders.
Your assets folder has been created on D:OpenServerdomainsasicapplibYiinitializrconfig/../../../../www.
Runtime ‘assets’ folders creation process finished.
Script YiinitializrComposerCallback::postPackageInstall handling the post-package-install event terminated with an exception

[CDbException]
CDbConnection failed to open the DB connection.

Do I miss something?

This comment has been minimized.

Copy link Quote reply

tonydspaniard commented May 28, 2013

file already exists. No action has been executed.

Remove your previous files installations or configure env.php database settings

This comment has been minimized.

Copy link Quote reply

bamburillo commented May 31, 2013

My env.php in D:OpenServerdomainsasicappconfig

Database "basic" in local MySQL exist.

And i still have error
[CDbException]

CDbConnection failed to open the DB connection.

This comment has been minimized.

Copy link Quote reply

tonydspaniard commented May 31, 2013

Whats in your other config files. Can I see?
Enviado desde mi BlackBerry® de Vodafone

——Original Message——
From: Vladimir Jucov notifications@github.com
Date: Fri, 31 May 2013 01:18:52
To: tonydspaniard/yiinitializr-basicyiinitializr-basic@noreply.github.com
Reply-To: tonydspaniard/yiinitializr-basic reply@reply.github.com
Cc: Antonio Ramirezantonio@ramirezcobos.com
Subject: Re: [yiinitializr-basic] Got Error "CDbConnection failed to open the
DB connection." (#8)

My env.php in z:openserverdomainsasicappconfig

And i still have error
[CDbException]

CDbConnection failed to open the DB connection.

Reply to this email directly or view it on GitHub:
#8 (comment)

This comment has been minimized.

Copy link Quote reply

bamburillo commented May 31, 2013

even if uncomment the db in common.php — the error remains.

This comment has been minimized.

Copy link Quote reply

bamburillo commented May 31, 2013

if I just take all the default configuration, and doing composer install , I get this error.

This comment has been minimized.

Copy link Quote reply

tonydspaniard commented May 31, 2013

Whats on your console ? Did you setup your console properly? When you run composer install after installation it runs the composer callback hook, calling the console , thus its configuration.

This comment has been minimized.

Copy link Quote reply

bamburillo commented May 31, 2013

This is var_dump() of configuration array appending composer callback methods

This comment has been minimized.

Copy link Quote reply

belkaaa commented Jun 6, 2013

On "yiinitializr-basic" is the same problem as in "yiinitializr-intermediate".

This comment has been minimized.

Copy link Quote reply

tonydspaniard commented Sep 1, 2013

But your database connection is set. I really do not understand how it doesn’t work. We tested and work with all project templates without issues.

This comment has been minimized.

Copy link Quote reply

nicolasbotanic commented Oct 20, 2013

Same here. I found that it was a driver issue, I just forgot to install php5-mysql in my debian box. But error message were not helpful because of this:

catch(PDOException $e)
<
if(YII_DEBUG)
<
throw new CDbException(‘CDbConnection failed to open the DB connection: ‘.
$e->getMessage(),(int)$e->getCode(),$e->errorInfo);
>
else
<
Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,’exception.CDbException’);
throw new CDbException(‘CDbConnection failed to open the DB connection.’,(int)$e->getCode(),$e->errorInfo);
>
>

. YII_DEBUG was false when I was running php composer.phar install.. so I couldn’t see $e->getMessage() response
and I don’t know where is sent the message through Yii::log()

This comment has been minimized.

Copy link Quote reply

DenisOgr commented Oct 23, 2013

I have this problem too. How it fix?
I download basic from http://yiinitializr.2amigos.us/
I unzip in my root folder.
Use
denis@denis-linux:/home/www-data/www/yiin1$ php composer.phar self-update
Updating to version a2a70380c14a20b3f611d849eae7342f2e35c763.
Downloading: 100%
denis@denis-linux:/home/www-data/www/yiin1$ php composer.phar install
PHP Warning: Module ‘memcache’ already loaded in Unknown on line 0
Yiinitialzr 1.0.1

  • download packages specified in composer.json
  • configures your runtime folders
  • triggers composer callbacks (yiic commands)

Start Installation? [y/n]: y
Start Installation? [y/n]: y
Loading composer repositories with package information
Installing dependencies (including require-dev)

  • Installing yiisoft/yii (1.1.14)
    Loading from cache

Please, enter your environment -ie. "dev | prod | stage": [dev]:

Building environment files.
Your environment configuration file has been created on /home/www-data/www/yiin1/app/lib/Yiinitializr/config/../../../config.

‘/home/www-data/www/yiin1/app/lib/Yiinitializr/config/../../../config/env.php’
file already exists. No action has been executed.
‘/home/www-data/www/yiin1/app/lib/Yiinitializr/config/../../../config/env.php’
file already exists. No action has been executed.
Environment files creation process finished.

Building runtime ‘runtime’ folders.
Your runtime folder has been created on /home/www-data/www/yiin1/app/lib/Yiinitializr/config/../../.
Runtime ‘runtime’ folders creation process finished.

Building runtime ‘assets’ folders.
Your assets folder has been created on /home/www-data/www/yiin1/app/lib/Yiinitializr/config/../../../../www.
Runtime ‘assets’ folders creation process finished.

  • Installing 2amigos/yiistrap (1.0.1)
    Loading from cache
  • Installing 2amigos/yiiwheels (1.0.3)
    Loading from cache

Writing lock file
Generating autoload files

Yii Migration Tool v1.0 (based on Yii v1.1.14)

Script YiinitializrComposerCallback::postInstall handling the post-install-cmd event terminated with an exception

[CDbException]
CDbConnection failed to open the DB connection.

install [—prefer-source] [—prefer-dist] [—dry-run] [—dev] [—no-dev] [—no-plugins] [—no-custom-installers] [—no-scripts] [—no-progress] [-v|vv|vvv|—verbose] [-o|—optimize-autoloader]