Code Duplication    Length = 41-41 lines in 2 locations

Sources/Subs-Db-mysql.php 1 location

@@ 876-916 (lines=41) @@
873
 * @param int $line What line of $file the code which generated the error is on
874
 * @return void|array Returns an array with the file and line if $error_type is 'return'
875
 */
876
function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
877
{
878
	if (empty($log_message))
879
		$log_message = $error_message;
880
881
	foreach (debug_backtrace() as $step)
882
	{
883
		// Found it?
884
		if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && strpos($step['function'], '__') !== 0)
885
		{
886
			$log_message .= '<br>Function: ' . $step['function'];
887
			break;
888
		}
889
890
		if (isset($step['line']))
891
		{
892
			$file = $step['file'];
893
			$line = $step['line'];
894
		}
895
	}
896
897
	// A special case - we want the file and line numbers for debugging.
898
	if ($error_type == 'return')
899
		return array($file, $line);
900
901
	// Is always a critical error.
902
	if (function_exists('log_error'))
903
		log_error($log_message, 'critical', $file, $line);
904
905
	if (function_exists('fatal_error'))
906
	{
907
		fatal_error($error_message, false);
908
909
		// Cannot continue...
910
		exit;
911
	}
912
	elseif ($error_type)
913
		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
914
	else
915
		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
916
}
917
918
/**
919
 * Escape the LIKE wildcards so that they match the character and not the wildcard.

Sources/Subs-Db-postgresql.php 1 location

@@ 879-919 (lines=41) @@
876
 * @param int $line What line of $file the code which generated the error is on
877
 * @return void|array Returns an array with the file and line if $error_type is 'return'
878
 */
879
function smf_db_error_backtrace($error_message, $log_message = '', $error_type = false, $file = null, $line = null)
880
{
881
	if (empty($log_message))
882
		$log_message = $error_message;
883
884
	foreach (debug_backtrace() as $step)
885
	{
886
		// Found it?
887
		if (strpos($step['function'], 'query') === false && !in_array(substr($step['function'], 0, 7), array('smf_db_', 'preg_re', 'db_erro', 'call_us')) && strpos($step['function'], '__') !== 0)
888
		{
889
			$log_message .= '<br>Function: ' . $step['function'];
890
			break;
891
		}
892
893
		if (isset($step['line']))
894
		{
895
			$file = $step['file'];
896
			$line = $step['line'];
897
		}
898
	}
899
900
	// A special case - we want the file and line numbers for debugging.
901
	if ($error_type == 'return')
902
		return array($file, $line);
903
904
	// Is always a critical error.
905
	if (function_exists('log_error'))
906
		log_error($log_message, 'critical', $file, $line);
907
908
	if (function_exists('fatal_error'))
909
	{
910
		fatal_error($error_message, $error_type);
911
912
		// Cannot continue...
913
		exit;
914
	}
915
	elseif ($error_type)
916
		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''), $error_type);
917
	else
918
		trigger_error($error_message . ($line !== null ? '<em>(' . basename($file) . '-' . $line . ')</em>' : ''));
919
}
920
921
/**
922
 * Escape the LIKE wildcards so that they match the character and not the wildcard.