Thinkphp mysql 数据库断线重连 MySQL server has gone away
2023-03-29 23:03:03
261
{{single.collect_count}}

数据库断线重连是指,在服务器出现某些原因导致数据库连接中断,需要启动重新连接数据库,并重新执行中断的数据库操作。Thinkphp5.0 是支持数据库断线重连的,代码很值得学习。它支持查询 query(包括select查询等读取操作),执行 execute (包括insert、update等写入操作)和 事务 startTrans() 的断线重连 这三种类型的数据库断线重连操作。

这个断线的判断是可配置的,需要将 config['break_reconnect'] 的值设置为 true, 才会执行断线判断。

database.php 配置文件中

//断线重连'break_reconnect' => true,

 

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}