這裏的是我寫的PHP代碼:PHP,MYSQL腳本無法連接到數據庫服務器
<?php
$con=mysqli_connect("193.167.138.9","username","password","DatabaseName");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$t_name = mysqli_real_escape_string($con, $_POST['name']);
$t_email = mysqli_real_escape_string($con, $_POST['email']);
//$age = mysqli_real_escape_string($con, $_POST['age']);
$ip = getenv("REMOTE_ADDR") ;
$date_time = date("l j F Y g:ia", time()- date("Z")) ;
$sql="INSERT INTO IP_TIME (Name, MAIL_ADDRESS,IP_ADDRESS,DATE_TIME)
VALUES ('$t_name', '$t_email', '$ip', '$date_time')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "Check the IP_TIME table";
mysqli_close($con);
?>
這裏193.167.138.9是我使用的服務器的IP。最初,當我在我的本地機器上測試它,在「193.167.138.9」的地方,這是「本地主機。
當我試圖在服務器上運行的代碼,它顯示了以下錯誤消息。
?Failed to connect to MySQL: Can't connect to MySQL server on '193.167.138.9' (111)Error:
任何想法,出了什麼問題,我該如何解決
我檢查它在MySQL配置文件,尤其是my.conf文件,它看起來象下面這樣:?
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#
bind-address = 127.0.0.1
不知道是什麼阻止mysql連接。任何幫助/建議將是有益的
嘗試'localhost'而不是'193.167.138.9' –
'無法連接到MySQL ...(111)錯誤:'你爲什麼要切斷錯誤信息...... – DanFromGermany