Host is not allowed to connect to this MySQL server

Hello
I’m having this problem were as I want to visit my php pages this error shows up:
Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000] [1130] Host ‘srv37.000webhost.com’ is not allowed to connect to this MySQL server’ in /home/a92XXXX73/public_html/includes/db.php:7 Stack trace: #0 /home/a92XXXX73/public_html/includes/db.php(7): PDO->__construct(‘mysql:host=DB_H…’, ‘DB_USERNAME’, ‘DB_PASSWORD’) #1 /home/a92XXXX73/public_html/Zaken.php(2): require_once(’/home/a92XXXX73/…’) #2 {main} thrown in /home/a92XXXX73/public_html/includes/db.php on line 7

This is the code where the error should be:


<?php
$mysql_host = "mysql12.000webhost.com";
$mysql_database = "a92XXXX_XXXX";
$mysql_user = "a92XXXXX_XXXX";
$mysql_password = "Private";

$odb = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD);
?>

Do you guys know how to fix this?
link to the error: http://projectabs.webatu.com/Zaken.php

You are defining db login details with mysql syntax, and then your actual connection uses PDO… the PDO definitions (“DB_HOST” etc) dont match the mysql definitions (“mysql_host”). Two different definitions using two different PHP functions.

Suggest using mysql connection instead of PDO, considering your mysql login details above are already correct…

DB CONFIG

$mysql_host = "mysql12.000webhost.com";
$mysql_database = "aXXXXXXX_db";
$mysql_user = "aXXXXXXX_user";
$mysql_password = "Private";

DB CONNECT

$connect = @mysql_connect($mysql_host, $mysql_user, $mysql_password)or die(mysql_error());
$db = @mysql_select_db($mysql_database,$connect)or die(mysql_error());

Doug u are very correct!!
This solution is perfect… All the php people use this only…
$connect = @mysql_connect($mysql_host, $mysql_user, $mysql_password)or die(mysql_error());
$db = @mysql_select_db($mysql_database,$connect)or die(mysql_error());

Try

<?php
$server = "localhost";
$username = "user";
$password = "password";
$db_name = "db name";
$connect = mysql_connect($server, $username, $password) or die (mysql_error());
mysql_select_db($db_name, $connect) or die (mysql_error());

mysql_query("SET NAMES utf8");
?>

also add your host name, database, username and password after “=” then try see this link

Original MySQL API

Warning

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

mysqli_connect()
PDO::__construct()

source : http://www.php.net/manual/en/function.mysql-connect.php

Forum Rules->Posting Rules->#10

This forum is intended for users to post useful snippets or applications for other users to utilize.
It is not intended to be a place where you post snippets of your malfunctioning code and ask for help.

A better forum to ask for help in would be here**, [URL=“http://www.000webhost.com/forum/web-design-html/”]here, or **[URL=“http://www.000webhost.com/forum/web-programming/”]here.

Please ask questions in their relevant forums and keep this site clean. You’ll benefit from faster, better responses to your problem.

very useful. thank you so much. appreciate.

thank you, now i understand.

Yup we also understand xD

Host ‘10.1.1.25’ is not allowed to connect to this MySQL server
how can i fix this error please help me

Notes:

  • Use your own version of PHPMyAdmin is not allowed
  • You have to create the database using MySQL icon before you can use it
  • It might take a few hours from the time you create or make any changes until it is available, please make sure you check using PHPMyAdmin first before you try to configure it with your application.
  • If you have a problem with your database, change your password or delete and create it and try again.
  • Remote Mysql is not allowed on free hosting, upgrade to paid hosting then you can do remote Mysql
  • Your config should point to MySQL hostname with ‘mysqlXX.000webhost.com’ format.
  • 000webhost version of PHPMyAdmin is connect using ‘sqlXX.000webhost.com’ format.

Please check Mysql icon in your cPanel for more connection detail

Free hosting server might be abuse at the time and it might not be available from time to time.