/var/www/(Del)hsihk.com/wp-content/plugins/backupbuddy/lib/wpdbutils/wpdbutils.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
 *    pluginbuddy_wpdbutils Class
 *
 *  Provides utility functions for helping with WordPress database handling
 *    
 *    Version: 1.0.1
 *    Author:
 *    Author URI:
 *
 *  @param        $db            object        Mandatory WordPress database object which is the database to operate on
 *    @return        null
 *
 */
if ( !class_exists"pluginbuddy_wpdbutils" ) ) {
    
    class 
pluginbuddy_wpdbutils {
        
        
// status method type parameter values - would like a class for this
        
const STATUS_TYPE_DETAILS 'details';

        public 
$_version '1.0.1';
        
        
/**
         * wpdb object 
         * 
         * @var wpdb
         */
        
protected $_db NULL;
        
        
/**
        * Whether or not mysqli is in use.
        */
        
protected $_using_mysqli false;
        
        
/**
         * parent object
         * 
         * @var parent object
         */
        
protected $_parent NULL;
        
        
/**
         * Whether or not we can call a status calback
         * 
         * @var have_status_callback bool
         */
        
protected $_have_status_callback false;
        
        
/**
         * Object->method array for status function
         * 
         * @var status_callback array
         */
        
protected $_status_callback = array();
        
        
        
/**
         *    __construct()
         *    
         *    Default constructor. Sets up optional status() function linkage if applicable.
         *    
         *  @param        reference    &$db            [mandatory] Reference to the database object
         *    @return        null
         *
         */
        
public function __construct( &$db ) { // removed wpdb type hint Jan 9, 2013.
            
            
$this->_db = &$db;
            
            
// As of WP 3.9 mysqli may be used.
            
if ( isset( $this->_db->use_mysqli ) && ( true === $this->_db->use_mysqli ) ) {
                
$this->_using_mysqli true;
                
$type 'mysqli';
            } else {
                
$type 'mysql';
            }
            
            
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS'Database kicker loaded. Database object class: `' get_class$db ) . '` with database of type `' $type '`.' );
        }
        
        
        
/**
         *    __destruct()
         *    
         *    Default destructor.
         *    
         *    @return        null
         *
         */
        
public function __destruct( ) {

        }
        
        
        
/**
         *    kick()
         *    
         *    Kicks the database to see if the conenction is still alive and if it isn't then tries to reconnect
         *    
         *    @return        true if connection alive (may have been reconnected), false otherwise (dead and couldn't be reconnected)
         *
         */
        
public function kick( ) {
            
            
// Initialize result to assume failure
            
$result false
            
            
// Use ping to check if server is still present - note will not reconnect automatically for MySQL >= 5.0.13
            // and actually we don't want it to as that is bad karma
            // mysqli added as of WP 3.9.
            
if ( ! $this->_mysql_ping() ) {
                
                
// Database connection appears to have gone away
                
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS__('Database Server has gone away, attempting to reconnect.','it-l10n-backupbuddy' ) );
                
                
// Close things down cleanly (from a local perspective)
                
if ( true === $this->_using_mysqli ) {
                    @
mysqli_close$this->_db->dbh );
                } else {
                    @
mysql_close$this->_db->dbh );
                }
                unset( 
$this->_db->dbh);
                
$this->_db->ready false;
                
                
// And attempt to reconnect
                
$this->_db->db_connect();
                
                
// Reconnect failed if we have a null resource or ping fails
                
if ( ( NULL == $this->_db->dbh ) || ( ! $this->_mysql_ping() ) ) {
                    
                    
// Reconnection failed, make sure user knows
                    
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS__('Database Server reconnection failed.','it-l10n-backupbuddy' ) );
                        
                    
// Make sure failure is notified (no need to close things down locally as it's a wrap anyway)
                    
$result false;
                    
                } else {
                    
                    
// Reconnection successful, make sure user knows
                    
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS__('Database Server reconnection successful.','it-l10n-backupbuddy' ) );
                    
$result true;
                    
                }
                
            } else { 
// Ping went through; still connected.
                
                // Just to let user know that database is still connected
                
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS__('Database Server connection status verified.','it-l10n-backupbuddy' ) );
                
$result true;
                
            }
            
            return 
$result;
        } 
// End kick().
        
        
        /* _mysql_ping()
         *
         * Ping mysql or mysqli as applicable.
         * @return    bool        Returns mysql[i] ping function response. (True on ping success, else false).
         */
        
private function _mysql_ping() {
            
            if ( 
true === $this->_using_mysqli ) {
                
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS__'Pinging mysqli.''it-l10n-backupbuddy' ) );
                return 
mysqli_ping$this->_db->dbh );
            } else {
                
pb_backupbuddy::statusself::STATUS_TYPE_DETAILS__'Pinging mysql.''it-l10n-backupbuddy' ) );
                return 
mysql_ping$this->_db->dbh );
            }
            
        } 
// End _mysql_ping().
        
        
    
// end pluginbuddy_wpdbutils class.
    
// end if !class_exists.