我有以下 PHP 代码可以连接到我的数据库:
I have the following PHP code to connect to my db:
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
?>
但是,我收到以下错误:
However, I get the following error:
Warning: mysql_connect() [function.mysql-connect]: [2002] A
connection attempt failed because the connected party did not (trying
to connect via tcp://localhost:3306) in C:Program Files (x86)EasyPHP-
5.3.2iwwwchecklogin.php on line 11
Warning: mysql_connect() [function.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. in C:Program Files (x86)EasyPHP-
5.3.2iwwwchecklogin.php on line 11
Fatal error: Maximum execution time of 30 seconds exceeded in
C:Program Files (x86)EasyPHP-5.3.2iwwwchecklogin.php on line 11
我可以通过 phpmyadmin 添加数据库/表,但我无法使用 PHP 连接.
I am able to add a db/tables via phpmyadmin but I can't connect using PHP.
这是我的 phpmyadmin 页面的屏幕截图:可能是什么问题?
Here is a screenshot of my phpmyadmin page: What could be the problem?
检查以下内容:
localhost
更改为 127.0.0.1
基本上,您收到的错误意味着它无法连接到服务器.它向 localhost:3306
发送请求,并且只等待这么长时间才能得到回复.它没有得到它,这意味着请求被阻止(防火墙)或被忽略(MySQL 没有运行和/或正在侦听不同的端口)
Basically, the errors you're getting mean that it cannot connect to the server. It sends request to localhost:3306
, and only waits so long for a reply. it's not getting it, which means the request is either blocked (firewall) or ignored (MySQL is not running and/or is listening on a different port)
如果 phpMyAdmin 随 MySQL 安装一起提供,那么它可能被配置为使用适当的不同端口
If phpMyAdmin came with the MySQL install, then it could be that it was configured to use the appropriately different port
这篇关于连接到 MySql DB (PHP) 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!