简体   繁体   English

php-mysql数据库连接

[英]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 我正在尝试连接到数据库以从sql工作台中检索表,但是当我这样做时,它会出现以下错误消息

could not connect to MySQL Unknown MySQL server host "Guada" 无法连接到MySQL未知的MySQL服务器主机“ Guada”

The php script is as follows: php脚本如下:

<?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. 我要检索的表在sql工作台上。

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? 您的php和MySQL是否都可以在某个地方的托管服务上运行?

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. 许多托管服务配置其内部网络,以便可以从运行在其内部服务器上的php访问MySQL,但不能直接从托管服务网络外部的客户计算机访问MySQL。 If you must access your MySQL directly from your home or office, ask your hosting service tech support for help. 如果您必须直接从家里或办公室访问MySQL,请向主机服务技术支持寻求帮助。

But keep in mind that you're running a security risk by opening up your MySQL database to access by the broader internet. 但是请记住,通过打开MySQL数据库以供更广泛的Internet访问会带来安全风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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