<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_25626"> <div class="blockcode"> <div id="code_hy7"><ol> <li> <li>function reconnect(){ </li> <li> if (!mysql_ping ($this->db)) { </li> <li> //here is the major trick, you have to close the connection (even though its not currently working) for it to recreate properly. </li> <li> mysql_close($this->db); </li> <li> $this->connect(); </li> <li> } </li> <li>} </li> <li> </li> </ol></div> <em onclick="copycode($('code_hy7'));">复制代码</em> </div>其中的mysql_ping()用来判断连接是否已经被断开了,若是断开了,关闭当前的链接,重新创建新的连接。 <br> 这样,只要发现连接被断开了,即可重新连接了。</td></tr></table> <div id="comment_25626" class="cm"> </div> <div id="post_rate_div_25626"></div> <br><br>