我有以下的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