Changeset 416


Ignore:
Timestamp:
Jul 3, 2013 1:00:48 PM (11 years ago)
Author:
anonymous
Message:

Added reconnect method to DB, and testing current connection status using mysql_ping.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/DB.inc.php

    r396 r416  
    161161            }
    162162
    163             // Die if db_die_on_failure = true, or just continue without connection
     163            // Die if db_die_on_failure = true, or just continue without connection.
    164164            return $this->_fail();
    165165        }
     
    190190            return false;
    191191        }
    192 
     192        $this->_connected = false;
    193193        return mysql_close($this->dbh);
     194    }
     195   
     196    /*
     197    *
     198    *
     199    * @access   public
     200    * @param   
     201    * @return   
     202    * @author   Quinn Comendant <quinn@strangecode.com>
     203    * @version  1.0
     204    * @since    03 Jul 2013 14:50:23
     205    */
     206    function reconnect()
     207    {
     208        $this->close();
     209        $this->connect();
    194210    }
    195211   
     
    284300            echo "<!-- ----------------- Query $this->_query_count ---------------------\n$debugqry\n-->\n";
    285301        }
     302       
     303        sleep(30);
     304       
     305        // Ensure we have an active connection.
     306        if (!mysql_ping($this->dbh)) {
     307            $app->logMsg('MySQL ping failed; reconnecting
', LOG_NOTICE, __FILE__, __LINE__);
     308            $this->reconnect();
     309        }
    286310
    287311        // Execute!
Note: See TracChangeset for help on using the changeset viewer.