1

I have had a lot of reading on this issue, but I have not found an answer.

I have a PDO connection to mariadb 10.5 through php7.4

My problem: If I go to the url directly on browser, the connection goes through. If I try to access from another php file through file_get_contents or cUrl, the error ocurrs.

$this->conn = new PDO("mysql:host=".$this->host.";dbname=".$dbname, $this->username, $this->password);

I have tried to use IP address, localhost, 127.0.0.1 as host to no avail.

I've also tried setting port=8889 like advised elsewhere, binding mariadb to 0.0.0.0 or even IP

Repeat: Problem happens only when called though another php script, or when my companion android app hits the php page. (Volley error) It doesn't occur when I load it through the browser. I feel like screaming.

Yeah, CentOS 8, Openlitespeed, Php 7.4, MariaDb 10.5

some of my reading n trials... PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused

Bonifes Maina
  • 33
  • 1
  • 6

1 Answers1

0

I have successfully solved the problem by dumping the database and re-importing it. Maybe 'something' had happened as I exported or imported the database through phpMyadmin.

Using ssh, I did:

mysqldump -u root database > database.sql;

Then login to mysql

mysql -u root; drop database..; create database...; \q; 

Then restore the dump

mysqldump -u root database < database.sql;

Voila! error gone. Whatever devil that was, it kept me busy reinstalling the vps, configuring the server and checking my code for a whole week.

Bonifes Maina
  • 33
  • 1
  • 6