Page 1 of 1

Can't connect to database in localhost via PHP

PostPosted: 03. February 2017 13:15
by Enorazza
My problem is: a fresh new XAMPP installation, everything seems fine.
PhpMyAdmin works nicely.
Websites cannot connect to DB.

It is like "localhost" is meaningless for the websites, while PMA doesn't give a damn, he just can do it..

OK I have tried lot of things, nothing worked so far:
* Turned off antivirus, skype, various other useless things.
* Ran as administrator XAMPP.
* Installed Apache and MySQL (mariadb) as services via XAMPP Control Panel.
* Changed default port to 8080.
* Forced ipv4.
* Used "127.0.0.1" string instead of "localhost" (as does PMA).
* Moved the website as a subfolder of xampp/htdocs (to try without configuring a virtualhost).
* Copied the same apache options of phpmyadmin.
* Used MariaDB 5.5 instead of the default 10.1
* Checked Mysql and Apache logs
* Googled a lot.
* Prayed various Gods.
* Looked at the screen for 10 minutes straight having a very angry face.
* Yelled bad words.

I have also WAMP, which works perfectly (of course is not running while testing XAMPP)
I am using XAMPP now just to have a fresh new and modern develpment environment for recent websites.

Any idea, please??

Re: Can't connect to database in localhost via PHP

PostPosted: 03. February 2017 16:50
by Altrea
full error message?

Re: Can't connect to database in localhost via PHP

PostPosted: 03. February 2017 16:53
by Enorazza
Already resolved.. never mind.

The weird thing is that, for whatever reason, the user for the database was not recognized in local.
I thought that in MySQL "%" meant "any host", and this in fact works in Linux.
I copied this in Windows, but it seems here instead I had to create also the "localhost" version of the Mysql user..
Dumb thing..

Re: Can't connect to database in localhost via PHP

PostPosted: 03. February 2017 17:13
by Altrea
Thats not fully correct.
MySQL/MariaDB does have a type of ranking which user is getting choosed if multiple users are fitting.
Wildcards does have less priority to specific data.

user@host
%@host
user@%
%@%

XAMPP already comes with a user %@localost, therefore this user will always has more priority than root@%.