0

I'm trying to connect to my database to retrieve the table from sql workbench, but when I do it comes up with the following error message

could not connect to MySQL Unknown MySQL server host "Guada"

The php script is as follows:

<?php

//Using details to establish database connection
DEFINE ('DB_USER', 'i7421760');
DEFINE ('DB PASSWORD', '*********');
DEFINE ('DB_HOST', 'guada');
DEFINE ('DB_NAME', 'i7421760');




$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('could not connect to MySQL ' .
        mysqli_connect_error());
/*
If the connection couldn't be established it 
will print a display message and the error report
*/
?>

If it is the case of just getting the host name wrong, where can I find it? The table I want to retrieve is on sql workbench.

Any help is appreciated thanks in advance

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

2 Answers2

1

Update your code:

//Using details to establish database connection
DEFINE ('DB_USER', 'i7421760');
DEFINE ('DB PASSWORD', '*********');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'i7421760');




$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('could not connect to MySQL ' .
        mysqli_connect_error());
/*
If the connection couldn't be established it 
will print a display message and the error report
PHP Ninja
  • 1,055
  • 2
  • 9
  • 28
  • When I change the host to local host, I get the following error message: could not connect to MySQL Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) – Nealington Dec 10 '16 at 13:30
  • Please check this http://stackoverflow.com/questions/4448467/cant-connect-to-local-mysql-server-through-socket-var-lib-mysql-mysql-sock – PHP Ninja Dec 12 '16 at 05:06
0

Is it possible your php and MySQL both run on a hosting service somewhere?

Many hosting services configure their internal networks so MySQL can be reached from php running on their internal servers, but not directly from customers' machines outside the hosting service networks. If you must access your MySQL directly from your home or office, ask your hosting service tech support for help.

But keep in mind that you're running a security risk by opening up your MySQL database to access by the broader internet.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • Yeah the host is elsewhere, I'm using my home laptop so that could be the problem there. I'll get in touch with the host to try resolve the issue. Thank you – Nealington Dec 10 '16 at 13:28