diff --git a/checkin_notes b/checkin_notes index b0658df7ca..40780051d1 100644 --- a/checkin_notes +++ b/checkin_notes @@ -9496,3 +9496,11 @@ David 18 Nov 2008 gui_rpc_server.cpp html/ops/ update_profile_pages.php + +David 18 Nov 2008 + - back-end programs: set MySQL option to reconnect to server + if the connection goes away + (which it apparently does if idle for a while) + + db/ + db_base.cpp diff --git a/db/db_base.cpp b/db/db_base.cpp index fe327c2135..279cf14721 100644 --- a/db/db_base.cpp +++ b/db/db_base.cpp @@ -41,8 +41,20 @@ DB_CONN::DB_CONN() { int DB_CONN::open(char* db_name, char* db_host, char* db_user, char* dbpassword) { mysql = mysql_init(0); if (!mysql) return ERR_DB_CANT_INIT; +#if MYSQL_VERSION_ID >= 50106 + my_bool mbReconnect = 1; + mysql_options(mysql, MYSQL_OPT_RECONNECT, &mbReconnect); +#endif mysql = mysql_real_connect(mysql, db_host, db_user, dbpassword, db_name, 0, 0, 0); if (mysql == 0) return ERR_DB_CANT_CONNECT; + + // older versions of MySQL lib need to set the option AFTER connecting; + // see http://dev.mysql.com/doc/refman/5.1/en/mysql-options.html + // +#if MYSQL_VERSION_ID >= 50013 && MYSQL_VERSION_ID < 50106 + my_bool mbReconnect = 1; + mysql_options(mysql, MYSQL_OPT_RECONNECT, &mbReconnect); +#endif return 0; }