简体   繁体   中英

php - mysql database connection

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM