I made a db on db4free.net, and I want to connect to it with php:
$username = myusername;
$password = mypw;
$host = "db4free.net:3306";
$dbname = mydbname;
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try
{
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
}
catch(PDOException $ex)
{
die("Failed to connect to the database: " . $ex->getMessage());
}
And I get this error message: Failed to connect to the database: SQLSTATE[HY000] [2005] Unknown MySQL server host
So I was thinking , that the hostname is wrong, so i tried to varie it a bit (adding /dbname or /username or removing the port, ect.). I've tried all the combinations, but none of them worked. The login data are checked multiple times. What could be the problem?
This may be too late to post an answer to this question.
But I hope this would help anyone who comes searching a solution for a connection failure or access denial just as me.
db4free.net while having database listening on the port 3306, they provide mysql servers on some other ports as well. When creating your account make sure to keep in mind the server you selected.
As in my case, my account was created on their newly set up mysql 8 server and it runs on the port 3307
This worked for me...
$host = "db4free.net";
I tried using this code and it worked for me
$host = "85.10.205.173:3306";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With