Im fighting with this problem since last week.
I have a project in php 5.6 with YII V.1. Im using MySQL 8.3 because is the only one permitted for my mac architecture.
I set up the project in a Docker and everything looks fine until the app ask me for the credentials
to get in. Once i press submit i get this error:
/var/www/html/fw/1.1.16/framework/db/CDbConnection.php(399)
387 throw new CDbException('CDbConnection.connectionString cannot be empty.');
388 try
389 {
390 Yii::trace('Opening DB connection','system.db.CDbConnection');
391 $this->_pdo=$this->createPdoInstance();
392 $this->initConnection($this->_pdo);
393 $this->_active=true;
394 }
395 catch(PDOException $e)
396 {
397 if(YII_DEBUG)
398 {
399 throw new CDbException('CDbConnection failed to open the DB connection: '.
400 $e->getMessage(),(int)$e->getCode(),$e->errorInfo);
401 }
402 else
403 {
404 Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
405 throw new CDbException('CDbConnection failed to open the DB connection.',(int)$e->getCode(),$e->errorInfo);
406 }
407 }
408 }
409 }
410 /**
I checked into the docker that DB is running okey and db credentials are ok.
INFO ABOUT SOCKETS:
yktoo-db | 2024-05-14T16:23:01.937766Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: ‘::’ port: 33060, socket: /var/run/mysqld/mysqlx.sock
yktoo-db | 2024-05-14T16:23:01.937783Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: ‘8.3.0’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 MySQL Commu
.YML file:
services:
app:
build:
context: .
dockerfile: ./Dockerfile-app
container_name: yktoo-app
ports:
- "80:80"
volumes:
- /Users/xxx/Desktop/sar/var/www/html:/var/www/html
db:
build:
context: .
dockerfile: ./Dockerfile-db
container_name: yktoo-db
environment:
MYSQL_ROOT_PASSWORD: "xxxx"
Here is the fragment of code for the connection:
'db'=>array(
'connectionString' => 'mysql:host=yktoodb;port=3306;dbname=phpmyadmin;
unix_socket=/var/run/mysqld/mysqld.sock', 'emulatePrepare' => true,
'username' => 'xxx',
'password' => 'xxx',
'charset' => 'utf8',`
Any ideas?? Thank u very much!
I tried changing the yktoo-db for the ip but it didnt work.
I tried using yktoo-db:3306 but it didnt work.
2
Answers
I tried those combinations:
Any ideas?
Your app is in one container and mysql database is on another container, meaning mysql is a remote database. Sockets can only be used for local connections, not for remote.
The solution is to use tcp connection with mysql container name or IP address as host name and whatever port you configured for mysql.