1

I have migrated a yii framework webapp to a 1&1 server and i am having troubles to connect with the database. The error is:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused

In my config/main.php i have this:

'db'=>array(
            'connectionString' => 'mysql:host=localhost:/tmp/mysql5.sock;dbname=nombrebasededatos',
            'emulatePrepare' => true,
            'username' => 'nombreusuario',
            'password' => 'password,',
            'charset' => 'utf8',
        ), 

Why can this be happening to me?

Sergio_HW
  • 155
  • 3
  • 18
  • 1&1 does not use localhost as host but each db has a specific hostname see https://help.1and1.com/hosting-c37630/linux-c85098/mysql-database-c37730/connect-to-your-mysql-database-using-php-a771846.html – Sam Jan 23 '14 at 21:13
  • can you write the code? please, because it doesnt work fine how i am writing – Sergio_HW Jan 23 '14 at 21:19

1 Answers1

0

As mentioned in the comments 1and1 does not use localhost as host and remove socket at the end so try

'db'=>array(
            'connectionString' => 'mysql:host=nombreusuario.db.1and1.com;dbname=nombrebasededatos',
            'emulatePrepare' => true,
            'username' => 'nombreusuario',
            'password' => 'password,',
            'charset' => 'utf8',
        ), 
Sam
  • 2,761
  • 3
  • 19
  • 30
  • CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known – Sergio_HW Jan 23 '14 at 21:25
  • Check http://stackoverflow.com/questions/8210099/php-php-network-getaddresses-getaddrinfo-failed-no-such-host-is-known – Sam Jan 23 '14 at 22:25