@@ -61,10 +61,9 @@ public function __construct($prefix = '') {
6161 if ($ this ->connect_error ) {
6262 $ this ->updateError ('DB::__construct ' );
6363 return false ;
64+ } else {
65+ $ this ->setCharacterEncoding ();
6466 }
65- parent ::query ( 'SET NAMES ' .$ this ->dbCharset );
66- parent ::query ( "SET character_set_results = ' " .$ this ->dbCharset ."', character_set_client = ' " .$ this ->dbCharset ."', character_set_connection = ' " .$ this ->dbCharset ."', character_set_database = ' " .$ this ->dbCharset ."', character_set_server = ' " .$ this ->dbCharset ."' " );
67-
6867 }
6968
7069 public function __destruct () {
@@ -89,14 +88,36 @@ public function updateError($location) {
8988 // This right here will allow us to use the samefile for server & interface
9089 if ($ this ->show_error_messages ) {
9190 echo $ error_msg ;
92- } else if (method_exists ($ app , 'log ' )) {
91+ } else if (is_object ( $ app ) && method_exists ($ app , 'log ' )) {
9392 $ app ->log ($ error_msg , LOGLEVEL_WARN );
9493 }
9594 }
9695 }
96+
97+ private function setCharacterEncoding () {
98+ parent ::query ( 'SET NAMES ' .$ this ->dbCharset );
99+ parent ::query ( "SET character_set_results = ' " .$ this ->dbCharset ."', character_set_client = ' " .$ this ->dbCharset ."', character_set_connection = ' " .$ this ->dbCharset ."', character_set_database = ' " .$ this ->dbCharset ."', character_set_server = ' " .$ this ->dbCharset ."' " );
100+ }
97101
98102 public function query ($ queryString ) {
99- parent ::ping ();
103+ $ try = 0 ;
104+ do {
105+ $ try ++;
106+ $ ok = parent ::ping ();
107+ if (!$ ok ) {
108+ if (!parent ::real_connect ($ this ->dbHost , $ this ->dbUser , $ this ->dbPass ,$ this ->dbName )) {
109+ if ($ try > 9 ) {
110+ $ this ->updateError ('DB::query -> reconnect ' );
111+ return false ;
112+ } else {
113+ sleep (1 );
114+ }
115+ } else {
116+ $ this ->setCharacterEncoding ();
117+ $ ok = true ;
118+ }
119+ }
120+ } while ($ ok == false );
100121 $ this ->queryId = parent ::query ($ queryString );
101122 $ this ->updateError ('DB::query( ' .$ queryString .') -> mysqli_query ' );
102123 if ($ this ->errorNumber ) debug_print_backtrace ();
@@ -184,10 +205,10 @@ public function diffrec($record_old, $record_new) {
184205 if (is_array ($ record_old ) && count ($ record_old ) > 0 ) {
185206 foreach ($ record_old as $ key => $ val ) {
186207 // if(!isset($record_new[$key]) || $record_new[$key] != $val) {
187- if ($ record_new [$ key ] != $ val ) {
208+ if (@ $ record_new [$ key ] != $ val ) {
188209 // Record has changed
189210 $ diffrec_full ['old ' ][$ key ] = $ val ;
190- $ diffrec_full ['new ' ][$ key ] = $ record_new [$ key ];
211+ $ diffrec_full ['new ' ][$ key ] = @ $ record_new [$ key ];
191212 $ diff_num ++;
192213 } else {
193214 $ diffrec_full ['old ' ][$ key ] = $ val ;
0 commit comments