简体   繁体   English

使用PHP连接到数据库

[英]Connect to database using PHP

I've made a database on my server but can't reach it. 我已经在服务器上建立了一个数据库,但是无法访问它。

I tried to connect to the database using php: 我试图使用php连接到数据库:

mysql_connect("$host", "$username", "$password")or die(mysql_error());

I get this message: 我收到此消息:

Warning : mysql_connect (): A connection attempt failed because the connected party did not properly respond after a period of time , or established connection failed because connected host has failed to respond. 警告:mysql_connect():连接尝试失败,因为连接的一方在一段时间后未正确响应,或者建立的连接失败,因为连接的主机未能响应。 in C: \\ xampp \\ htdocs \\ New Site Ron (app) \\ connection.php on line 7 在C:\\ xampp \\ htdocs \\ New Site Ron(app)\\ connection.php在第7行

Is it because I'm using xampp or is it something else? 是因为我正在使用xampp还是其他?

Thanks in advance, 提前致谢,

Sam 山姆


I fixed it by using my sever instead of using xampp. 我通过使用服务器而不是xampp修复了它。

I can't connect to MySQL at "thehostnameyouprovided.com" either ... not on port 3306 anyway. 我也无法通过“ thehostnameyouprovided.com”连接到MySQL,无论如何也无法在端口3306上进行连接。

So either the MySQL daemon/server isn't running there, or it's not running on TCP/IP 3306 (for example, it's only running on a local socket), or the server has a firewall that isn't allowing access to me from my IP address (and might not be allowing it to your from your address either). 因此,要么MySQL守护程序/服务器未在其中运行,要么未在TCP / IP 3306上运行(例如,它仅在本地套接字上运行),或者服务器具有不允许从中访问我的防火墙。我的IP地址(也可能不允许从您的地址将其发送给您)。

At any rate, making absolutely sure the server is accepting connections from your address on port 3306 should be your first line of inquiry. 无论如何,绝对要确保服务器正在接受来自端口3306上您地址的连接,这应该是您的第一行查询。

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

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