Db connection error?

Good evening,

I receive this error message (see print screen).
I think the connection line is correct? I created the db in phpAdmin.

Do you have an idea ?

<?php
// Debugging
ini_set('error_reporting', E_ALL);

// DATABASE INFORMATION
define('DATABASE_HOST', getenv('IP'));
define('DATABASE_NAME', 'invoicemgsys');
define('DATABASE_USER', 'root');
define('DATABASE_PASS', '');

// CONNECT TO THE DATABASE
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
?>

I think it is pretty explanatory, you are not using the right credentials. Are you sure root with an empty password is going to log you in? Have you tried using localhost instead of getenv('IP')?

The error basically tells you the credentials are wrong. So try some others.

Better yet, make some others. Dont use root to access your database.

1 Like

Good morning,

I changed user with a password and I still get an error message

Do you have an idea ?

// DATABASE INFORMATION
define('DATABASE_HOST', getenv('localhost'));
define('DATABASE_NAME', 'invoicemgsys');
define('DATABASE_USER', 'cdevl');
define('DATABASE_PASS', '12kirsi5');

// CONNECT TO THE DATABASE
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);

define('DATABASE_HOST', 'localhost');

(Assuming your database is running on localhost…)

I still have the same error message.

I do this well: define(‘DATABASE_HOST’, ‘localhost’);

and it’s on localhost

Try “127.0.0.1” instead of localhost.

Have you changed the port number? Why does your PHPMyAdmin register that it’s connected to 3308? The default should be 3306.
Have you got multiple instances of MariaDB/MySQL running?

yes I had a problem and I had to change port.

Should I change a few things?

$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
=>
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME, 3308);

(obviously, if you want to define a constant for it, you could)

1 Like

great thank you, it works like that.

Does it pose a problem afterwards when I want to transfer everything to my host?

If your host is running on the default port, obviously you’ll have to change the port back. If you leave the port variable empty (like you did for the original line), PHP will assume 3306 as a default.

1 Like

ok thank you very much for your help.

Good Sunday

1 Like

I am used to add DATABASE_PORT also. But DATABASE_HOST may contain the database port?