問題描述
我知道有很多這樣的問題,但我沒有找到任何解決方案.
I know there are many questions like this, but i didn't find any solution in it.
我嘗試過的事情:-
檢查防火墻
checked firewall
重新啟動了我的電腦和 Apache 服務器
restarted my PC and Apache server
重啟MYSQL
檢查了我的代碼
嘗試了我在互聯網上知道和找到的一切
Tried everything i know and found on internet
這是我的代碼:-
<?php
$dbhost = 'localhost:3360';
$dbuser = 'root';
$dbpass = '';
$db = 'test_db13';
$conn = mysqli_connect($dbhost,$dbuser,'',$db);
if(! $conn){
die('Could not connect connect: ') ;
}
echo 'Successfully Connected';
$sql = 'Connected Successfully';
$retvalue = mysqli_query($sql);
if(! $retvalue){
die('Cannot connect to SQL: ');
}
echo 'DataBase test_db13 has successfully created';
mysqli_close($conn);
?>
我確實設置了密碼,但它仍然顯示錯誤.
I did set the password, but it still is showing me the error.
這是防火墻圖片:-
最后 XAMMP 正在運行,這是證明
lastly XAMMP is running here's the proof
推薦答案
如果你看看你的 XAMPP 控制面板,它清楚地說明 MySQL 服務器的端口是 3306
- 你提供了 3360
.3306
是默認的,因此不需要指定.即便如此,mysqli_connect()
的第 5 個參數是端口,也就是應該指定的地??方.
If you look at your XAMPP Control Panel, it's clearly stated that the port to the MySQL server is 3306
- you provided 3360
. The 3306
is default, and thus doesn't need to be specified. Even so, the 5th parameter of mysqli_connect()
is the port, which is where it should be specified.
您可以完全刪除端口規范,因為您使用的是默認端口,使其成為
You could just remove the port specification altogether, as you're using the default port, making it
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'test_db13';
參考資料
mysqli_connect()
- MySQL 標準連接
這篇關于mysqli_connect(): (HY000/2002): 由于目標機器主動拒絕,無法建立連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!