Cdbconnection failed to open the db connection

New Page

CDbException: CDbConnection could not open database connection

I started getting this error while trying to do a yiic migration on my experimental project.

CDbException: CDbConnection could not open database connection

Googling I realized that pdo_mysql.sono was present as a module in my PHP installation. So I had to recompile PHP 5.2.10, with the

‘–con-pdo-mysql=/usr/local/mysql/bin/mysql_config’

configured option.

This fixed the problem!

I also added –with-mysql and –with-mysqlq to the config. With this you can remove the mysql.so extension in php.ini, as the old MySQL configuration would no longer require a dynamic extension.

To verify that MySql PDO is installed, type php -m and verify that there is an entry for pdo_mysql.

CDbConnection could not open DB Yii connection

Ask

Asked 8 years, 6 months ago

Modified 4 years, 3 months ago

Seen 19,000 times

Report this ad

This question shows research effort; it is useful and clear

3

This question shows no research effort; unclear or not useful

Please mark this question.

View activity on this post.

When I try to connect to mysql with plain PHP it works fine. My code

$link = mysql_connect(‘hostname’, ‘username’, ‘password’); if (!$link) { die(‘Failed to connect’); } if(mysql_select_db(‘dbname’)){ echo ‘Connected successfully’; }

But when I try to connect with yii I get the error

myconfig/main.php

‘db’=>array( ‘class’=>’CDbConnection’, ‘connectionString’ => ‘mysql:host=hostname;dbname=dbname’, ’emulatePrepare’ => true, /* I’m also trying false*/ ‘ username ‘ => ‘username’, ‘password’ => ‘password’, ‘charset’ => ‘utf8’, ),

This is the output of the exception I print in the open() function framework/db/CDbConnection.php Exception handle here

protected function open() { if($this->_pdo===null) { if(empty($this->connectionString)) throw new CDbException(‘CDbConnection.connectionString cannot be empty.’); try { Yii::trace(‘Opening database connection’, ‘system.db.CDbConnection’); $this->_pdo=$this->createPdoInstance(); $this->initConnection($this->_pdo); $this->_active=true; } catch(PDOException $e) { echo ‘<pre>’; var_dump($e); die; if(YII_DEBUG) { throw new CDbException(‘CDbConnection failed to open database connection: ‘. $e->getMessage(),(int)$e->getCode(),$e- >errorInfo); } else { Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,’exception.CDbException’); throw new CDbException(‘CDbConnection n’ failed to open database connection.’,(int)$e->getCode(),$e->errorInfo); } } } }

exception text

“SQLSTATE[HY000] [2054] The server requested an authentication method unknown to the client”

I see on the screen

CDbException CDbConnection failed to open the database connection.

My PHP VERSION 5.5.36 Mysql version 5.5.35 My hosting is i-page dot com Yii Version ‘1.1.13’ Thanks for the help.

  • php
  • mysql
  • yii

To share

Share a link to this question

Copy link CC BY-SA 3.0

Follow

Follow this question to receive notifications

requested on April 2, 2014 at 3:00 p.m.

styopdev user avatar

styopdev styopdev

2,564 4 4 gold badges 32 32 silver badges 54 54 bronze badges

of them

  • 1

    Je vérifie juste, mais le tableau ‘db’ est-il dans le tableau ‘components’ de votre main/config.php? Pouvez-vous également coller comment vous utilisez la fonction d’ouverture de CDbConnection ?

    – ews2001

    2 avril 2014 à 20:56

  • Votre problème lié à pdo appelez votre hébergeur pour l’installer ou consultez ce lien stackoverflow.com/questions/13375061/…

    –Ahmad Samilo

    3 avril 2014 à 5:46

Ajouter un commentaire | 

2 réponses2

Trié par : Réinitialiser par défaut

Score élevé (par défaut) Tendance (les votes récents comptent plus) Date de modification (le plus récent en premier) Date de création (le plus ancien en premier)

Cette réponse est utile

1

Cette réponse n’est pas utile

Afficher l’activité sur ce post.

There seems to be a problem with the way passwords are hashed and the version of MySQL and the MYSQL_PDO library.

Yii uses PDO to query the database, that’s why plain PHP works like a charm and Yii doesn’t.

To verify this, try this:

$mysqlConnection = new PDO(“mysql:host=hostname;dbname= dbname”, “username”, “password”);

this line should return the following error:

PDO::__construct(): The server requested authentication method unknown to the client [mysql_old_password].

This error is the equivalent to the MySQL 2045:

“SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

If you confirm that the problem is related to PDO you have several options but you need to access the hosting system (or ask them to fix the problem):

  • Sign in to MySQL and execute the following command SET PASSWORD FOR ‘username’@’hostname’ = OLD_PASSWORD(‘password’); (this will fix the hashing of the password)
  • Upgrade the MYSQL PDO Library (PDO_MYSQL) to match the version of MYSQL on the server.

Share

Share a link to this answer

Copy link CC BY-SA 3.0

Follow

Follow this answer to receive notifications

answered Apr 3, 2014 at 3:36 PM

User avatar of javierfdezg

javierfdezg javierfdezg

2,067 1 1 gold badge 21 21 silver badges 31 31 bronze badges

1

  • Hi, thanks for the reply. But I don’t have webserver admin permission because I just use web hosting, I think hosting admin need to do it. When I have solved this problem, I will post the solution.

    – styopdev

    April 3, 2014 at 7:02 PM

Add a comment | 

This answer is helpful

1

This answer is not helpful

View activity on this post.

I had this problem with the Yii 1.1.x project and almost went crazy:

First make sure you have

sudo apt install php-xml php-mbstring php-pdo php-mysql

installed and restart apache

sudo apachectl restart

Where:

sudo apache2 service restart

The detailed error was that the database library could not be found .

My solution was related to caching:

cache’ => array( ‘class’ => ‘system.caching.CDbCache’, //’class’ => ‘system.caching.CFileCache’, ‘connectionID’=>’db’, // <<< C’ IS THE PROBLEM),

si connectionID n’est pas défini, la mise en cache de la base de données utilise par défaut la base de données mysqli dans le répertoire /protected/data qui n’est pas accessible si le pilote mysqli n’est pas installé sur le système (problème courant avec les serveurs dédiés, les gouttelettes DO, xampp/wamp …)

ou, vous pouvez désactiver la mise en cache db et activer fileCache à la place.

Compartir

Partager un lien vers cette réponse

Copier le lien CC BY-SA 4.0

Suivre

Suivez cette réponse pour recevoir des notifications

modifié le 3 juin 2018 à 17:22

User avatar of alexander.polomodov

Alexandre Polomodov

5 220 14 14 insignes d’or 39 39 insignes d’argent 44 44 insignes de bronze

répondu le 3 juin 2018 à 16:59

raptor user avatar

rapace rapace

341 3 3 insignes d’argent 7 7 insignes de bronze

Ajouter un commentaire | 

Ta Réponse

Merci d’avoir contribué à une réponse à Stack Overflow !

  • Please be sure to answer the question. Provide details and share your research!

But avoid…

  • Ask for help, clarification, or respond to other responses.
  • Make statements based on opinion; back them up with references or personal experience.

To learn more, check out our tips for writing great responses.

saved draft

Draft rejected

Sign up or log in

Sign up with Google

Sign up using Facebook

Sign up using your email and password

Submit

Post as guest

Yam

E-mail

Required, but never displayed

Post as guest

Yam

E-mail

Required, but never displayed

Post your answer Ignore

By clicking “Post your answer” you agree to our Terms of Service, Privacy Policy and Cookies Policy

Not the answer you are looking for? Browse other tagged questions

  • php
  • mysql
  • yii

or ask your own question.

  • The overflow blog
  • Stack Overflow Trends: Weekday and Weekend Site Activity

  • For developers, flow status starts at their fingertips 

  • Featured in Meta
  • Recent color contrast changes and accessibility updates

  • Reviewer overboard! Or a request to improve the onboarding guide for new…

  • Do I need to explain other people’s answers in code?

  • Collective update: recognized members, articles and GitLab

Report this ad

Related

3036

Should I use datetime or timestamp data type in MySQL?

2712

How can I get YouTube video thumbnail from YouTube API?

2591

How to import an SQL file using the command line in MySQL?

0

When testing external Mysql connection I get CDbConnection could not open database connection

0

Error in CDbException when hosting yii app on godaddy

0

“CDbConnection could not open database connection: driver not found” when trying to generate a model class

1

SQLSTATE[HY000][1049] on YiiFramework

burning questions from the net

  • Genesis 22:19 – Where is Isaac?
  • Create a snack shortcut
  • Expectation of the number of men sitting between two specific women
  • How do you know when it’s time to ditch the tires?
  • Dangerous sorcery and lingering damage
  • When Artemis lacks perspective
  • How to Fix an Underwater Power Line
  • Why can’t you just say “My sister made me a doll”?
  • How does the SQL database engine swap the values ​​of two columns?
  • How to get rid of a large amount of wet sugar?
  • How do non-English speakers navigate JFK airport?
  • Do all solids sublime at low enough temperature and pressure?
  • What caused the nervousness in the DART video when he approached Dimorphos?
  • Is there a way to calculate the spectral effect of a nonlinear function?
  • How to answer the interviewer’s question “How was the interview?” Do they ask you a few days after the job interview on the phone?
  • What are the disadvantages of redistributing eBGP routes in IGP?
  • Could a pine forest survive year-round snowfall?
  • How is the expected approach time expressed in ATC communications?
  • Can anyone explain why the sterling dollar peg is bad?
  • A man drives the last gas-guzzling car. . . but he has a secret
  • What is the largest airplane ever flown and successfully landed without a pilot on board?
  • How to identify this Bianchi model?
  • Binary classification cross-validation ROC score: only consider higher confidence class probabilities
  • Did Henry Kissinger call Bangladesh a bottomless basket?

question flow

Subscribe to RSS

question flow

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Video Cdbconnection failed to open the db connection

Related Posts

Fatal error require failed opening required

Contents1 Fatal error of PHP No se pudo to open the archive requerido2 Subscribe to RSS3 About WPML3.1 From day one, our priorities have remained the same…

Your media file could not be processed.

Contents1 Fixed: Twitter Error “Your media file could not be processed”1.1 freno de mano1.2 ClipChamp Créer1.3 FilmoraGo1.4 adobe sparkle2 Video Your media file could not be processed….

Gravity forms not sending email

Contents1 [SOLVED] Why doesn’t Gravity Forms send email?1.1 How does Gravity Forms send email?1.2 Résoudre les problèmes liés aux formulaires Gravity qui n’envoient pas d’e-mail1.3 Configure Gravity…

This webpage is not founderr_file_not_found

Contents1 Install and manage extensions1.1 Install trusted extensions1.2 Agregar o eliminar el acceso a un sitio específico1.3 Hide extensions1.4 Show extensions2 5 Ways To Permanently Fix Chrome…

Continue to this website not recommended missing

Contents1 Ignore the “Continue to this website (not recommended)” message1.1 publication information1.2 Information1.3 Contents1.4 Admin Items2 Internet Explorer 10 ‘Continue to this website’ is missing option2.1 Similar…

Error loading stream id not found on server

Contents1 JWPlayer 6 error message “Error loading stream: ID not found on server”1.1 Inscrivez-vous ou connectez-vous1.2 Post as guest1.3 Post as guest2 Subscribe to RSS3 Problems with…