问题描述
我有以下 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?
推荐答案
检查以下内容:
- MySQL 是否正在运行?
- 是否有任何防火墙会阻止您的计算机接受端口 3306 上的 MySQL 连接?
- MySQL 是在侦听端口 3306,还是更改为非标准的端口?
- 很奇怪,但尝试从
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) 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)