我有以下的PHP代码连接到我的分贝:麻烦连接到MySQL数据库(PHP)
<?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连接。
以下是我的phpmyadmin页面的屏幕截图: 可能是什么问题?
这是一个家庭服务器?我有主机,我无法通过本地主机连接。 – Galen 2010-05-04 21:01:24
@galen好,因为phpMyAdmin是工作,我们可以假设它的工作在localhost – nc3b 2010-05-04 21:03:18
@ nc3b:我不同意。如果你检查人员的答案,你会发现我是对的。 – Galen 2010-05-04 22:58:19