php连接mysql超时的解决方法

原创
2016-07-25 09:05:38 1084浏览
  1. function reconnect(){
  2. if (!mysql_ping ($this->db)) {
  3. //here is the major trick, you have to close the connection (even though its not currently working) for it to recreate properly.
  4. mysql_close($this->db);
  5. $this->connect();
  6. }
  7. }
复制代码
其中的mysql_ping()用来判断连接是否已经被断开了,若是断开了,关闭当前的链接,重新创建新的连接。
这样,只要发现连接被断开了,即可重新连接了。


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。