vizvan
January 2, 2017, 2:17pm
#1
[Sorry to post in a new thread – the previous thread was closed and can’t post more]
Still unable to connect MySQL server on ‘mysql8.000webhost.com ’. I got the old control panel.
Investigation: MySQL server (mysql8.000webhost.com ) is NOT reachable from the web-server (mybudget.netne.net ).
details of connecting/ping from webserver:
Failed to connect to MySQL: Can’t connect to MySQL server on ‘mysql8.000webhost.com ’ (113)
Warning: fsockopen() [function.fsockopen]: unable to connect to mysql8.000webhost.com:3306 (Connection timed out) in /home//public_html/test.php
Can you try the three methods down the middle of the tutorial to see if any work for connection?
Introduction
You can create databases on 000webhost.com and PHP can be used to connect to those databases. This tutorial explains three different methods how that could be achieved. Most of the websites need to have at least one database and if you are developing a website from the beginning you will have to connect it to a database manually, here you can find how that could be done step by step.
What you'll need
Before you begin this guide you'll need the following:
Understanding of PHP …
Method 1 — Connecting to the database using PDO (recommended)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";
try {
$conn = new PDO("mysql:host=$servername;dbname=$database", $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();
}
?>
Method 2 — Connecting to the database using mysqli (Object-Oriented)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Method 3 — Connecting to the database using mysqli_connect (Procedural)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
vizvan
January 2, 2017, 2:45pm
#3
I use method 2 to connect. Unfortunately, it did not work.
Warnings/Error:
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003): Can’t connect to MySQL server on ‘mysql8.000webhost.com ’ (113)
Connection failed: Can’t connect to MySQL server on ‘mysql8.000webhost.com ’ (113)
I even can’t seem to ping the MySQL server from my local machine or the web-server [1-2].
[1] http://stackoverflow.com/questions/9841635/how-can-i-ping-a-server-port-with-php
[2] http://stackoverflow.com/questions/1239068/ping-site-and-return-result-in-php
I know remote connections to MySQL are blocked in the free hosting so you can’t remotely connect but since your script is on your hosting I’m not sure why it can’t access the database.
vizvan
January 2, 2017, 3:15pm
#5
How can I check the status of the mysql server in the same spirit as [1]? Others [2] are facing problems connecting to mysql8.
[1] http://status.000webhost.com/
[2] Is there something wrong with mysql host: mysql8.000webhost.com
I just use status.000webhost.com to keep an eye on uptime etc.
http://status.000webhost.com/778339538
As far as I can see the database server is still functioning?
http://sql8.000webhost.com/phpMyAdmin/
vizvan
January 2, 2017, 3:35pm
#7
Yes, phpmyadmin is working. This happened last time where phpmyadmin was working but was unable to connect with php [1]. Then, was able to connect the very next day.
Any changes to firewall rules at your end? or upgrades?
[1] Unable to mysqli_connect()@mysql8 today -- mysql8 down?
vizvan
January 3, 2017, 1:56am
#8
Still down, James. I’ll try tomorrow to check if any change in status.
vizvan
January 3, 2017, 11:45pm
#9
When I try to open phpMyAdmin [2], it gives me a blank page. I do NOT see “mysql8.000webhost” anywhere on [1]. Others seem to have problems connecting [3,4]. Not sure what else I can do? reach out to community?
[1] http://status.000webhost.com/778339538
[2] http://sql8.000webhost.com/phpMyAdmin/
[3] Unable to connect to mysql with 000webhost
[4] Is there something wrong with mysql host: mysql8.000webhost.com
pi3l3
January 4, 2017, 1:56pm
#11
I am also experiencing the same issue. I went through any other fix that I could find (change pwd, new db, even reinstalling wordpress), but no success.
This happens since 2 days ago on my side.
vizvan
January 5, 2017, 1:36am
#12
vizvan
January 6, 2017, 1:37am
#13
i can now connect to MySQL. Thanks James for answering my queries. Thanks staff member for resolving this issue.