根據(jù)官方文檔:Checks whether the connection to the server is working. If the connection has gone down and auto-reconnect is enabled an attempt to reconnect is made. If the connection is down and auto-reconnect is disabled, mysql_ping() returns an error.也就是說,如果 MYSQL_OPT_RECONNECT 沒有被設(shè)置為 1(開啟),那么mysql_ping()不會(huì)完成自動(dòng)重連,只是簡(jiǎn)單返回一個(gè)error。那么如果已經(jīng)開啟這個(gè)選項(xiàng)了呢?官方文檔又說了:MYSQL_OPT_RECONNECT (argument type: my_bool *)Enable or disable automatic reconnection to the server if the connection is found to have been lost.也就是說,如果發(fā)現(xiàn)連接斷開,那么會(huì)啟動(dòng)自動(dòng)重連功能。現(xiàn)在問題是:連接斷開這事兒是啥時(shí)候被發(fā)現(xiàn)的呢?根據(jù)官方文檔mysql_ping()肯定是會(huì)發(fā)現(xiàn),那mysql_query()是否會(huì)"發(fā)現(xiàn)"呢?
2 回答

紫衣仙女
TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
需要的,不加ping的話鏈接斷開的情況下query會(huì)失敗但是會(huì)重連下次query才會(huì)正常,所以封裝下query比較穩(wěn)
添加回答
舉報(bào)
0/150
提交
取消