Welcome Guest, Not a member yet? Register   Sign In
CI4 + Lando (docker) - Main connection [MySQLi]: No such file or directory
#1

(This post was last modified: 07-16-2021, 03:31 AM by CCAldo. Edit Reason: Did check connection, and inserted new item )

I'm having some issues setting up CodeIgniter 4 with Lando.
CI4 is unable to connect to the MySQL database.

Code:
"Unable to connect to the database.
Main connection [MySQLi]: No such file or directory"


CI3 has no issues with this matter.

Lando uses a lamp database with these settings

Code:
host: 'database', port: '3306', database: 'lamp', password: 'lamp', user: 'lamp'

The CI4 database.php has been changes with this:

Code:
public $lando = [
'DSN'      => '',
'hostname' => 'database',
'username' => 'lamp',
'password' => 'lamp',
'database' => 'lamp',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug'  => (ENVIRONMENT !== 'production'),
'charset'  => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre'  => '',
'encrypt'  => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port'     => 3306,
];
$this->defaultGroup = 'lando';


``mysql status`` shows me that UNIX socket is located at this location:
Code:
/opt/bitnami/mysql/tmp/mysql.sock

So I added this line to php.ini
Code:
; MySQLi
mysqli.default_socket = /opt/bitnami/mysql/tmp/mysql.sock

But the issue persist.

My docker container:
[Image: pMpIhsq.png]

EDIT:
When checking connection with below code the result is 'Connected succesfully'.
And inserted new news-item also trows no error

Code:
// Check connection
if ($conn->connect_error) {
dd("Connection failed: " . $conn->connect_error);
}
dump("Connected successfully");

$sql = "INSERT INTO news (news_title, news_slug, news_description) VALUES ('Title', 'title', 'Lorem ipsum')";
if (mysqli_query($conn, $sql)) {
$last_id = mysqli_insert_id($conn);
dump("New record created successfully. Last inserted ID is: " . $last_id);
} else {
dd("Error:", $sql, mysqli_error($conn));
}


Does anyone having the same issue?
Or is Ci4 not able to work with MySQL in docker containers?
Reply


Messages In This Thread
CI4 + Lando (docker) - Main connection [MySQLi]: No such file or directory - by CCAldo - 07-16-2021, 01:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB