From 43c5718bba1892cfe4e653bccfd69a4b31b6bb3a Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 11 Sep 2011 13:06:27 +0200 Subject: [PATCH] reconnect to mysql if disconnected --- mysqlConn.c | 13 ++++++++++--- mysqlConn.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/mysqlConn.c b/mysqlConn.c index 53b50e9..66494e7 100644 --- a/mysqlConn.c +++ b/mysqlConn.c @@ -16,9 +16,16 @@ static struct used_result *used_results; static struct escaped_string *escaped_strings; void check_mysql() { - if(mysql_ping(mysql_conn)) { - //mysql error - show_mysql_error(); + int errid; + if((errid = mysql_ping(mysql_conn))) { + if(mysql_errno(mysql_conn) == CR_SERVER_GONE_ERROR) { + if(!mysql_real_connect(mysql_conn, MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_BASE, MYSQL_PORT, NULL, 0)) { + show_mysql_error(); + } + } else { + //mysql error + show_mysql_error(); + } } } diff --git a/mysqlConn.h b/mysqlConn.h index f456471..4ed6655 100644 --- a/mysqlConn.h +++ b/mysqlConn.h @@ -3,6 +3,7 @@ #include "main.h" #include +#include #define MYSQLMAXLEN 1024 -- 2.20.1