MySQL Database Error

I’m having issues getting my PHP website connected to a MySQL database. I followed the instructions online, have my website setup with an SFTP connection pointed to the correct folder. The website connection is successful when I do “Check” at the bottom.

I’m able to connect to the MySQL database from my webserver using a MySQL client and the same username/password. So it’s not a port problem or a user permissions problem.

The first time I enter the settings and hit test connections, I get this error:

If I don’t close the window and hit “Test Connection” again, I get this error:

Capture3

It’s odd, because if I test the connection the website, it works fine. If I update the website html/php files, everything updates.

I’m at a loss at this point. Any help or guidance is appreciated.

John

Check your FTP settings are correctly pointing to the root of your site.
Wappler uploads a connection script to the webserver before making the database connection, if the target is not set correctly then the script conenction fails and you will get symptoms like this

Thanks, Hyperbytes.

The settings do look correct:

I’ve tried it with the “Active” both checked and unchecked. That’s definitely the root of my website and if I hit the “publish” button I get no warnings (and the Test Connection always works).

To me it looks that the ftp connection is not the problem, the second error seems to be because the script was not uploaded correctly or didn’t response. But in the first error it did response with an error that it couldn’t connect to the mysql server.

You say that you where able to connect to the database from the web server, was this with a PHP script and did you use the same connection settings?

I connected directly with the mysql-client in CentOS.

I’ll try manually making a PHP script in the same website and see if that works.

Thanks for the suggestion.

Edit: If I do “php -m” on my server, it looks like PDO is installed:

image

Okay, I get the same error with a simple PHP page that looks like this:

 <?php
$servername = "localhost";
$username = "username";
$password = "password";

try {
    $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
?> 

So it is NOT a wappler problem. I’ll report back when I figure it out.

Thanks again everyone.

When all else fails, blame SELinux!

Turns out that you need to turn on network connections for httpd when SELinux is enabled. The command is:

sudo setsebool httpd_can_network_connect_db on

Found here: https://unix.stackexchange.com/questions/318729/sqlstatehy000-2003-cant-connect-to-mysql-server-on-127-0-0-1-13-but-lo

Thanks again Patrick and Hyperbytes.

1 Like