![](/img/trans.png)
[英]Can't connect to database with error (HY000/2002): No connection could be made because the target machine actively refused it
[英]error to connect database, target machine actively refused it
我正在開發一個應用程序,其中連接了數據庫的兩個表,但沒有連接第三個表。 (這是在服務器上。它們在我的本地計算機上工作正常。)
1. Warning: mysql_connect() [function.mysql-connect]: [2002] No
connection could be made because the target machine actively (trying
to connect via tcp://localhost:3306) in D:\Hosting.. on line 5
2. Warning: mysql_connect() [function.mysql-connect]: No connection could be made because the target machine actively refused it. in D:\Hosting.. on line 5
在較早的階段,我成功地從同一數據庫連接了兩個表,因此我檢查了數據庫中每個表的物理位置。 難怪所有人都物理地位於數據庫中的同一位置。
請幫助我理解問題。
編輯:
//Page1 has something like:
$conid=mysql_connect("dxxs.db.7xx7.hostedresource.com","dxxs","Kxx3") or die();
mysql_select_db("dxxs",$conid) or die();
mysql_query(“some basic 4-5 queries depending on user’s interaction with table1”);
mysql_close($conid);
//redirection to page2 from there to page3
$conid=mysql_connect("dxxs.db.7xx7.hostedresource.com","dxxs","Kxx3") or die();
mysql_select_db("dxxs",$conid) or die();
mysql_query(“some basic 4-5 queries depending on user’s interaction with table2”);
mysql_close($conid);
//some redirection to page4
$conid=mysql_connect("dxxs.db.7xx7.hostedresource.com","dxxs","Kxx3") or die();
mysql_select_db("dxxs",$conid) or die();
mysql_query(“some basic 4-5 queries depending on user’s interaction with table3”);
mysql_close($conid);
現在我的問題是連接到表3時,服務器拋出了如上所述的錯誤
在第5行的地方,編寫了MySQL_connect。 請幫助我了解為什么表3未連接而表1和表2能夠連接。 所有這些都駐留在服務器上的同一數據庫中。
聽起來您正在為要使用的每個表調用一次mysql_connect()
。 您不需要執行此操作-您只需要為正在使用的每個服務器連接一次即可。
服務器可能將您限制為2個並發連接,這就是為什么它拒絕第三個連接的原因。
嘗試在腳本頂部調用一次mysql_connect()
。
我找到了問題並解決了。 嘗試在hostname:PORT
之后使用port使用我的代碼:
$dbh=@mysql_connect('dbxxxxxx.db.1and1.com:3306','db-username','db-password');
if (!$dbh) {
$err_msg='Cannot connect to the database because: '.mysql_error();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.