Error: incorrect database name

Trying to query a database with PHP, I get the following error:

Fatal error : Uncaught PDOException: SQLSTATE[HY000] [1102] Incorrect database name 'persons ’ in /opt/lampp/htdocs/Uebung3-Datenbank/services/querydatabase.php:3 Stack trace: #0 /opt/lampp/htdocs/Uebung3-Datenbank/services/querydatabase.php(3): PDO->__construct(‘mysql:host=loca…’, ‘root’, ‘’) #1 {main} thrown in /opt/lampp/htdocs/Uebung3-Datenbank/services/querydatabase.php on line 3

Well, the database’s name is definitely “persons” - when I run SELECT DATABASE() on it,
persons is returned.

I also have another DB running on this PC, and changing the name in the PHP file to this one’s, I get the same error.

$pdoObject = new PDO("mysql:host=localhost; dbname=beb-uebung3-produkt ; charset=utf8", "root", "");
1 Like

It’s this line I posted above. Here’s the whole file:

<?php

$pdoObject = new PDO("mysql:host=localhost; dbname=beb-uebung3-produkt ; charset=utf8", "root", "");

$sql = "SELECT id, name FROM product_types ORDER BY name;";

$resultTable = array();
try {
    //iterieren für alle moeglichen zeilen
    foreach ($pdoObject -> query($sql) as $row) {
        $resultTable[] = $row;  //die Zeile in den Array schreiben
    }
} catch (PDOException $exception) {
    //error handling, wenn die Anfrage schief ging
    error_log("PDO ERROR: querying database: " . $exception->getMessage()."\n".$sql);

    print_r($resultTable);
}

This code is supposed to connect to a database called beb-uebung3-produkt.
I relaized that I may have messed with the configuration of XAMPP by moving the file index.php from the webroot to one of its subfolders that I created, thinking it contained one of my exercises. Moving the file back to its original location didn’t help, so I decided to do a complete reinstall of XAMPP to be on the safe side.
Never worry though, I still get an error calling the file in my browser under http://localhost/Uebung3-Datenbank/services/querydatabase.php. It’s changed to this now:

Fatal error : Uncaught PDOException: SQLSTATE[HY000] [2002] File or directory not found in /opt/lampp/htdocs/Uebung3-Datenbank/services/querydatabase.php:3 Stack trace: #0 /opt/lampp/htdocs/Uebung3-Datenbank/services/querydatabase.php(3): PDO->__construct(‘mysql:host=loca…’, ‘root’, ‘’) #1 {main} thrown in /opt/lampp/htdocs/Uebung3-Datenbank/services/querydatabase.php on line 3

this same line, again…
I checked on the database in PHPMyadmin, and sure enough, it’s not connecting anymore:

There isn’t any login mask for entering credentials, this screen is shown immediately.
I don’t know what the correct setting are for MySQL - I can’t remember setting any settings in my previous working install

You re-installed XAMPP and got this result without touching anything?

PHPMyAdmin should work right out the box, without configuring anything. I think the credentials are root for login and an empty password by default, but that doesn’t even seem the be the issue here…

I’d try getting rid of XAMPP completely and attempt a clean re-install? This is odd.

It is. A clean re-install of XAMPP is what I just did and got this error. phpMyAdmin doesn’t come as a part of XAMPP, does it?

It does, here’s all that’s included in XAMPP

Inclusions: Apache 2.4.46, MariaDB 10.4.14, PHP 7.4.9 + SQLite 2.8.17/3.32.3 + multibyte (mbstring) support, Perl 5.32.0, ProFTPD 1.3.6, phpMyAdmin 5.0.2, OpenSSL 1.1.1g, GD 2.2.5, Freetype2 2.4.8, libpng 1.6.37, gdbm 1.8.3, zlib 1.2.11, expat 2.0.1, Sablotron 1.0.3, libxml 2.0.1, Ming 0.4.5, Webalizer 2.23-05, pdf class 0.11.7, ncurses 5.9, pdf class 0.11.7, mod_perl 2.0.11, FreeTDS 0.91, gettext 0.19.8.1, IMAP C-Client 2007e, OpenLDAP (client) 2.4.48, mcrypt 2.5.8, mhash 0.9.9.9, cUrl 7.53.1, libxslt 1.1.33, libapreq 2.13, FPDF 1.7, ICU4C Library 66.1, APR 1.5.2, APR-utils 1.5.4

I did a reinstall downloading the package from the XAMPP website this time (my previous install was from my distro’s repository). Now MySQL won’t even run, phpMyAdmin displays more errors than before (sorry they’re all in German).

Willkommen bei phpMyAdmin

Fehler

MySQL meldet:

Die Verbindung konnte aufgrund von ungültigen Einstellungen nicht hergestellt werden.

mysqli::real_connect(): (HY000/2002): Datei oder Verzeichnis nicht gefunden

Verbindung für den controluser, wie er in Ihrer Konfiguration angegeben ist, ist fehlgeschlagen.

mysqli::real_connect(): (HY000/2002): Datei oder Verzeichnis nicht gefunden

phpMyAdmin hat versucht eine Verbindung zum MySQL-Server aufzubauen und die Verbindung wurde zurückgewiesen. Sie sollten Ihre Einstellungen für Host, Benutzername und Passwort in Ihrer config.inc.php überprüfen und sich vergewissern, dass diese den Informationen, die Sie vom Administrator erhalten haben, entsprechen.

Could both be conflicting? Did you modify anything?

Could it be related to what you did here? How to edit PHP code which is under webroot (needs root access...)

Haham I had the same thought there :smile:
Maybe MySQL takes issue with the fact that webroot is no longer owned by root, but by my user?
It was suggested on an Ubuntu help page to solve this problem, one should symlink the userland folder that we edit our files to the XAMPP webroot:

sudo ln -s ~/FOLDERNAME /opt/lampp/htdocs/$USER 

How would you go about it?

Well I removed the one from repositories first and all of its remaining files. The installer from the homepage and my distro’s package manager both install XAMPP to the same folder, so I made sure that was emtpy.

I’m now positive that it’s all due to

sudo chown -R ben:ben /opt/lampp/htdocs

Don’t see any other potential reason… could you revert this back to what it was?


Or… try to check:

Benutzername und Passwort in Ihrer config.inc.php

Guess you’d have to change root with ben and see what the password is? But I’m not sure this would even work. Worth a try though if you don’t want to/can’t revert back to root?

Usually you don’t touch root, just add more users.


Wish I could be of more help but this isn’t exactly my area of expertise if I’m honest…

I did another clean re-install from the repository again, because with that one, the MySQL server would at least start. That means owner of XAMPP now is also root again.
I did as suggested here and symlinked my userland working directory under webroot. To make this work, I also had to replace daemon in the entries
User: daemon and
Group: daemon in the /opt/lampp/etc/httpd.conf file with my user ben.
MySQL now runs again, but phpMyAdmin gives my the same error as before.

I did this and now I can get into phpmyadmin:
Changed user to ben in /opt/lampp/phpmyadmin/config.inc.php , the password is empty.
It’s displaying weird errors, but at least I can use it now!

EDIT: I’m forbidden from creating a new database. No permission. I don’t know what to do. Surely there must be some way to write PHP code and run it without changing users?

1 Like

What kind of errors?

Cannot create new database, no permission

Benutzer “@‘localhost’”

That’s problematic. Should be root@localhost, or ben@localhost or something


After Plugins (top-right), there should be a “More” tab, that gives you access to a “User accounts” tab. Try checking that to see which users have access, and with which privileges.

I can’t find a “More” tab… :slightly_frowning_face:

This version (which comes with XAMPP) might have some restrictions…

What if you try to access localhost/phpmyadmin/server_privileges.php?viewing_mode=server

So that’s a dead end…

Perhaps trying to find a way to add a root user again? I’m not entirely sure