Tbiks
February 13, 2026, 7:57am
1
hi i have a problem with my php, mariadb, i can’t solve the problem with fatal error
is there anyone with some help ?
Fatal error: Uncaught mysqli_sql_exception: Access denied for user ‘username’@‘localhost’ in /home/hans/mysqli_connect.php:14 Stack trace: #0 /home/hans/mysqli_connect.php(14): mysqli_connect(‘localhost’, ‘username’, Object(SensitiveParameterValue), ‘sitename’) #1 /home/hans/view_users.php(10): require_once(‘/home/hans/mysq…’) #2 {main} thrown in /home/hans/mysqli_connect.php on line 14
the line 14 referred to is:
// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
maba77
February 13, 2026, 9:02am
2
I think you need to provide more information. The error is not releated to nix.
Verify constants (DB_) are set properly and check if user in DB_USER is allowed to connect from localhost.
Tbiks
February 13, 2026, 10:16am
3
hi, I see a possibility that db_user has too do white my login on the mariadb server
I log in to mariadb with,
sudo mariadb sitename;
which gives root as user, I can’t understand that since I created the database with the following, andlogin as sitename_user fails
MARIADB> CREATE DATABASE sitename CHARACTER SET utf8 COLLATE utf8_general_ci;
MARIADB> CREATE USER ‘sitename_user’@‘localhost’ IDENTIFIED BY ‘12345678’;
MARIADB> GRANT ALL ON sitename.* TO ‘sitename_user’@‘localhost’;
MARIADB> USE ‘sitename’;
MARIADB> select authentication_string from mysql.user where user = ‘sitename_user’;
when login on sitename, and execute \s I get this
MariaDB [sitename]> \s
mariadb Ver 15.1 Distrib 10.11.13-MariaDB, for Linux (x86_64) using readline 5.1
Connection id: 9Current database: sitenameCurrent user: root@localhostSSL: Not in useCurrent pager: stdoutUsing outfile: ‘’Using delimiter: ;Server: MariaDBServer version: 10.11.13-MariaDB MariaDB ServerProtocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8mb4Db characterset: utf8mb3Client characterset: utf8mb3Conn. characterset: utf8mb3UNIX socket: /run/mysqld/mysqld.sock
maba77
February 13, 2026, 1:52pm
4
sudo mariadb sitename;
which gives root as user, I can’t understand that since I created the database with the following, andlogin as sitename_user fails
The mariadb client uses Linux username by default (sudo → root).
To connect with created credentials, you have to do something like
mariadb --user sitename_user --password sitename
(sitename is the database name)
Tbiks
February 13, 2026, 2:38pm
5
yes that is a different account !
but how do i then connect too localhost do you haw a suggestion ?
Current user: sitename_user@localhost
maba77
February 13, 2026, 2:49pm
6
I expect localhost to be the default if --host option is not set.
Are PHP and mariadb are running on the same machine/server?
Tbiks
February 13, 2026, 4:40pm
7
yes php and mariadb is on my pc both started from the terminal, and localhost/8000 is the one used when test php html file i the Firefox browser.
is the –host to go in the login sequence or in the php file
Tbiks
February 15, 2026, 1:18pm
8
I have tested ‘–host’ but no effect, login as sudo or as user shows no difference result from before.
from mariadb manual S57 there is that line
some systems come with an anonymous localhost user, and when connecting from localhost this will take
precedence.
is it possible of localhost is anonymous and what can I do about it
maba77
February 15, 2026, 2:31pm
9
It’s hard to help debugging with the provided information.
May be this helps: Troubleshooting Connection Issues Guide | Server | MariaDB Documentation
The problem is not Nix-specific and, in my opinion, is better suited to a PHP forum.
Tbiks
February 18, 2026, 3:08pm
10
the problem is solved
it seems there were a lot of different errors the first thing i did was run ‘GRANT SELECT’
GRANT SELECT, INSERT, UPDATE, DELETE ON sitename.* TO ‘root’@‘localhost’ IDENTIFIED BY ‘12345678’;
and then a change in ‘DEFINE’ that makes a difference, where I change ‘username’ to ‘root’
DEFINE (‘DB_USER’, ‘root’);
there after a new login
sudo mariadb --user root -p --port=3306 sitename
and then php error there was an error with a ‘CONCAT’ which had survived from a previous script, so now it works!!
maba77
The problem is not Nix-specific and, in my opinion, is better suited to a PHP forum.
and you were right, thank you very much for the help