1111 */
1212class ezsqlModel extends ezQuery implements ezsqlModelInterface
1313{
14- protected $ isSecure = false ;
14+ protected $ isSecure = false ;
1515 protected $ secureOptions = null ;
1616 protected $ sslKey = null ;
1717 protected $ sslCert = null ;
@@ -139,7 +139,7 @@ class ezsqlModel extends ezQuery implements ezsqlModelInterface
139139 * Needed for echo of debug function
140140 * @var boolean Default is false
141141 */
142- protected $ debug_echo_is_on = true ;
142+ protected $ debug_echo_is_on = false ;
143143
144144 /**
145145 * Whether the database connection is established, or not
@@ -214,10 +214,7 @@ public function get_host_port( $host, $default = false )
214214 return array ( $ host , $ port );
215215 }
216216
217- /**
218- * Print SQL/DB error - over-ridden by specific DB class
219- */
220- public function register_error ($ err_str )
217+ public function register_error (string $ err_str , bool $ displayError = true )
221218 {
222219 // Keep track of last error
223220 $ this ->last_error = $ err_str ;
@@ -226,7 +223,12 @@ public function register_error($err_str)
226223 $ this ->captured_errors [] = array (
227224 'error_str ' => $ err_str ,
228225 'query ' => $ this ->last_query
229- );
226+ );
227+
228+ if ($ this ->show_errors && $ displayError )
229+ \trigger_error (\htmlentities ($ err_str ), \E_USER_WARNING );
230+
231+ return false ;
230232 }
231233
232234 public function show_errors ()
@@ -265,8 +267,7 @@ public function log_query(string $query)
265267 \array_push ($ this ->all_func_calls , $ this ->func_call );
266268 }
267269
268- public function get_var (string $ query = null , int $ x = 0 , int $ y = 0 ,
269- bool $ use_prepare = false )
270+ public function get_var (string $ query = null , int $ x = 0 , int $ y = 0 , bool $ use_prepare = false )
270271 {
271272 // Log how the function was called
272273 $ this ->log_query ("\$db->get_var( \"$ query \", $ x, $ y) " );
@@ -285,8 +286,7 @@ public function get_var(string $query = null, int $x = 0, int $y = 0,
285286 return (isset ($ values [$ x ]) && $ values [$ x ] !== null ) ? $ values [$ x ] :null ;
286287 }
287288
288- public function get_row (string $ query = null , $ output = OBJECT , int $ y = 0 ,
289- bool $ use_prepare = false )
289+ public function get_row (string $ query = null , $ output = OBJECT , int $ y = 0 , bool $ use_prepare = false )
290290 {
291291 // Log how the function was called
292292 $ this ->log_query ("\$db->get_row( \"$ query \", $ output, $ y) " );
@@ -311,8 +311,7 @@ public function get_row(string $query = null, $output = OBJECT, int $y = 0,
311311 }
312312 }
313313
314- public function get_col (string $ query = null , int $ x = 0 ,
315- bool $ use_prepare = false )
314+ public function get_col (string $ query = null , int $ x = 0 , bool $ use_prepare = false )
316315 {
317316 $ new_array = array ();
318317
@@ -332,8 +331,7 @@ public function get_col(string $query = null, int $x = 0,
332331 return $ new_array ;
333332 }
334333
335- public function get_results (string $ query = null , $ output = \OBJECT ,
336- bool $ use_prepare = false )
334+ public function get_results (string $ query = null , $ output = \OBJECT , bool $ use_prepare = false )
337335 {
338336 // Log how the function was called
339337 $ this ->log_query ("\$db->get_results( \"$ query \", $ output, $ use_prepare) " );
@@ -358,10 +356,8 @@ public function get_results(string $query = null, $output = \OBJECT,
358356 }
359357 $ i ++;
360358 }
361- return $ new_array ;
362- } else {
363- return array ();
364359 }
360+ return $ new_array ;
365361 }
366362 }
367363
@@ -377,14 +373,15 @@ public function get_col_info(string $info_type = "name", int $col_offset = -1)
377373 }
378374
379375 return $ new_array ;
380- } else {
381- return $ this ->col_info [$ col_offset ]->{$ info_type };
382376 }
377+
378+ return $ this ->col_info [$ col_offset ]->{$ info_type };
383379 }
384380 }
385381
386382 /**
387383 * create cache directory if doesn't exists
384+ *
388385 * @param string $path
389386 */
390387 public function create_cache (string $ path = null )
@@ -396,10 +393,7 @@ public function create_cache(string $path = null)
396393 }
397394 }
398395
399- /**
400- * store_cache
401- */
402- public function store_cache (string $ query , bool $ is_insert )
396+ public function store_cache (string $ query , bool $ is_insert = false )
403397 {
404398 // The would be cache file for this query
405399 $ cache_file = $ this ->cache_dir .\_DS .\md5 ($ query );
@@ -410,8 +404,7 @@ public function store_cache(string $query, bool $is_insert)
410404 ) {
411405 $ this ->create_cache ();
412406 if ( ! \is_dir ($ this ->cache_dir ) ) {
413- $ this ->register_error ("Could not open cache dir: $ this ->cache_dir " );
414- $ this ->show_errors ? \trigger_error ("Could not open cache dir: $ this ->cache_dir " , \E_USER_WARNING ) : null ;
407+ return $ this ->register_error ("Could not open cache dir: $ this ->cache_dir " );
415408 } else {
416409 // Cache all result values
417410 $ result_cache = array (
@@ -428,9 +421,6 @@ public function store_cache(string $query, bool $is_insert)
428421 }
429422 }
430423
431- /**
432- * get_cache
433- */
434424 public function get_cache (string $ query )
435425 {
436426 // The would be cache file for this query
0 commit comments