reconnect to mysql if disconnected
authorpk910 <philipp@zoelle1.de>
Sun, 11 Sep 2011 11:06:27 +0000 (13:06 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 11 Sep 2011 11:17:24 +0000 (13:17 +0200)
mysqlConn.c
mysqlConn.h

index 53b50e995ce3f495c435a94bcc69b52446b07533..66494e7f5055cf333db9d500c9bde2a605c7f2cd 100644 (file)
@@ -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();
+        }
     }
 }
 
index f456471b6444ccab62186a3da059455286bec282..4ed66558136797691052986110fe3a1ee555ee1b 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "main.h"
 #include <mysql.h>
+#include <mysql/errmsg.h>
 
 #define MYSQLMAXLEN 1024