Can't connect to database in localhost via PHP

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Can't connect to database in localhost via PHP

Postby Enorazza » 03. February 2017 13:15

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??
Enorazza
 
Posts: 2
Joined: 03. February 2017 12:46
XAMPP version: 5.6.30
Operating System: Windows 7 x64

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

Postby Altrea » 03. February 2017 16:50

full error message?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

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

Postby Enorazza » 03. February 2017 16:53

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..
Enorazza
 
Posts: 2
Joined: 03. February 2017 12:46
XAMPP version: 5.6.30
Operating System: Windows 7 x64

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

Postby Altrea » 03. February 2017 17:13

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@%.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 137 guests