2012-04-03 29 views
0

我遇到MySQL服務器通過PHP代碼跟隨在MySQL數據庫中存儲API結果的反應消失API響應的結果已經離我們遠去,MySQL服務器中存儲的PHP

$api_response = sendmsg($group_detail['cell_no'], $SMS); //function to execute API 

    //update sms sent record 
$sql = "INSERT INTO sms_sent_record (record_id, api_response) 
         VALUES (NULL, '$api_response')"; 
$result = mysql_query($sql) or die('Error, updating sms & group count    
       in sms_sent_count failed : ' . mysql_error()); 

我已經嘗試了許多其他選項,比如將api響應存儲在數組中,然後將其存儲在mysql表中,但以任何方式拋出相同的錯誤。服務器不會執行此錯誤後的其他代碼。

我認爲這是由於延遲在API中的響應和超時問題。

有什麼辦法可以避免這個錯誤並以正確的方式存儲結果。

+0

錯誤是什麼? – safarov 2012-04-03 11:58:27

+0

「MYSQL服務器已經消失」是一個實際的錯誤。最無助的一個可能,但一個錯誤無一例外。它的工作原理是 – SpaceBeers 2012-04-03 12:32:03

回答

0

請問如果省略SENDMSG做工作? 如果是這樣,您可能希望存儲第一次連接到數據庫時的鏈接並重新使用它。

$link=mysql_connect(); 
.. 
.. 
mysql_query($sql,$link); 
+0

。但sql只記錄前兩個響應...其餘的代碼根本不運行。 – shuja 2012-04-10 12:11:23

+0

$ api_response通常是什麼樣的? - 你也可以使用'$ api_response = mysql_real_escape_string($ api_response);' – jornare 2012-04-10 14:18:24

0

There are lots of reasons for the gone away message但我懷疑你的問題是,你打開API調用之前您的數據庫連接(發送SMS?)和API調用導致服務器端INSERT運行之前,連接

嘗試打開的數據庫連接移動到之前的INSERT聲明:

$api_response = sendmsg($group_detail['cell_no'], $SMS); //function to execute API 
// open connection here 
$sql = "INSERT INTO sms_sent_record (record_id, api_response) 
         VALUES (NULL, '$api_response')"; 
$result = mysql_query($sql) or die('Error, updating sms & group count    
       in sms_sent_count failed : ' . mysql_error()); 

檢查值wait_timeout這個設置是

服務器在關閉之前等待非交互連接的活動的秒數。

如果您將此值設置得很低,服務器將超時打開連接和運行查詢之間的連接。

$api_response = 'test';//sendmsg($group_detail['cell_no'], $SMS); //function to execute API 

如果是這樣,SENDMSG()使用某種隨時MySQL連接的: