@@ -122,7 +122,7 @@ class MySQL_wrapper {
122122 * @param string $password - MySQL Password
123123 * @param string $database - MySQL Database
124124 */
125- function MySQL_wrapper ($ server = NULL , $ username = NULL , $ password = NULL , $ database = NULL ){
125+ function MySQL_wrapper ($ server = NULL , $ username = NULL , $ password = NULL , $ database = NULL ) {
126126 $ this ->server = $ server ;
127127 $ this ->username = $ username ;
128128 $ this ->password = $ password ;
@@ -174,6 +174,23 @@ function setCharacter($character, $link = 0) {
174174 else return FALSE ;
175175 }
176176
177+ /** Checks whether or not the connection to the server is working.
178+ * @param resurse $link - Link identifier
179+ * @return boolean
180+ */
181+ function ping ($ link = 0 ) {
182+ return mysql_ping ($ link ? $ link : $ this ->link );
183+ }
184+
185+ /** Reconnect to the server.
186+ * @param resurse $link - Link identifier
187+ * @return boolean
188+ */
189+ function reconnect ($ link = 0 ) {
190+ $ this ->close ($ link ? $ link : $ this ->link );
191+ return $ this ->connect ();
192+ }
193+
177194 /** Close Connection on the server that's associated with the specified link (identifier).
178195 * @param resurse $link - Link identifier
179196 */
@@ -361,7 +378,7 @@ function importCSV2Table($file, $table, $delimiter = ',', $enclosure = '"', $esc
361378 * @param resource $link - Link identifier
362379 * @return - File path
363380 */
364- function exportTable2CSV ($ table , $ file , $ columns = '* ' , $ where = NULL , $ limit = 0 , $ delimiter = ', ' , $ enclosure = '" ' , $ escape = '\\' , $ newLine = '\n ' , $ showColumns = TRUE , $ link = 0 ){
381+ function exportTable2CSV ($ table , $ file , $ columns = '* ' , $ where = NULL , $ limit = 0 , $ delimiter = ', ' , $ enclosure = '" ' , $ escape = '\\' , $ newLine = '\n ' , $ showColumns = TRUE , $ link = 0 ) {
365382 $ this ->link = $ link ? $ link : $ this ->link ;
366383 $ fh = fopen ($ file , 'w ' ) or ($ this ->logErrors ) ? $ this ->log ("ERROR " , "Can't create CSV file. " ) : FALSE ;
367384 fclose ($ fh );
@@ -422,7 +439,7 @@ function query2CSV($sql, $file, $delimiter = ',', $enclosure = '"', $escape = '\
422439 $ sql = trim (rtrim (trim ($ sql ), '; ' ));
423440 // Prepare SQL for column names
424441 if ($ showColumns ) {
425- $ r = $ this ->query (preg_replace ('/limit(([\s]+[\d]+[\s]*,[\s]*[\d]+)|([\s]+[\d]))$/i ' , 'LIMIT 1 ' , $ sql ), $ this ->link );
442+ $ r = $ this ->query (preg_replace ('/limit(([\s]+[\d]+[\s]*,[\s]*[\d]+)|([\s]+[\d]))$/i ' , 'LIMIT 1; ' , $ sql ), $ this ->link );
426443 if ($ r !== FALSE && $ this ->affected > 0 ) {
427444 $ columns = $ this ->fetchArray ($ r );
428445 $ this ->freeResult ($ r );
@@ -499,7 +516,7 @@ function dropTable($table, $if_exists = TRUE, $link = 0) {
499516 */
500517 function getDataBaseSize ($ sizeIn = 'MB ' , $ round = 2 , $ link = 0 ) {
501518 $ this ->link = $ link ? $ link : $ this ->link ;
502- $ r = $ this ->query ("SELECT ROUND( SUM( `data_length` + `index_length` ) " . str_repeat ('/ 1024 ' , array_search (strtoupper ($ sizeIn ), array (0 => 'B ' , 1 => 'KB ' , 2 => 'MB ' , 3 => 'GB ' , 4 => 'TB ' ))) . ", {$ round } ) `size` FROM `information_schema`.`TABLES` WHERE `table_schema` LIKE ' {$ this ->database }' GROUP BY `table_schema`; " , $ this ->link );
519+ $ r = $ this ->query ("SELECT ROUND( SUM( `data_length` + `index_length` ) " . str_repeat ('/ 1024 ' , array_search (strtoupper ($ sizeIn ), array ('B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' ))) . ", {$ round } ) `size` FROM `information_schema`.`TABLES` WHERE `table_schema` LIKE ' {$ this ->database }' GROUP BY `table_schema`; " , $ this ->link );
503520 if ($ r !== FALSE ) {
504521 $ row = $ this ->fetchArray ($ r );
505522 $ this ->freeResult ($ r );
@@ -697,4 +714,3 @@ function getMicrotime() {
697714 return ((float ) $ usec + (float ) $ sec );
698715 }
699716}
700-
0 commit comments