本文介绍了连接到MySql DB(PHP)时遇到麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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");

?>

但是,出现以下错误:

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.2i\www\checklogin.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.2i\www\checklogin.php on line 11

Fatal error: Maximum execution time of 30 seconds exceeded in
C:\Program Files (x86)\EasyPHP-5.3.2i\www\checklogin.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?

推荐答案

检查以下内容:

  1. MySQL是否正在运行?
  2. 是否存在任何防火墙可能会阻止您的计算机在端口3306上接受与MySQL的连接?
  3. MySQL是在侦听端口3306,还是将其更改为非标准端口?
  4. 一个奇怪的,但尝试从localhost更改为127.0.0.1
  1. Is MySQL running?
  2. Is there any firewall that could be blocking your computer from accepting connections to MySQL on port 3306?
  3. Is MySQL listening on port 3306, or did it get changed to something nonstandard?
  4. An odd one, but try changing from localhost to 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)时遇到麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:37