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

3
  • 4
    Usually host is localhost or 127.0.0.1 Commented Dec 10, 2016 at 12:37
  • NOTE: SQL Workbench is a tool used to simplify MYSQL database management not a database MYSQL is the DBMS Commented Dec 10, 2016 at 12:38
  • So, you got Unknown MySQL server host "Guada"' - why do you think that is? Commented Dec 10, 2016 at 12:38

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

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)
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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.