<?php
error_reporting(0);
############ Website Database Communication Functions##########

function db_query($sql) {
	$dbcon	= $GLOBALS['dbconn'];
	$result	= mysqli_query($dbcon,$sql) or	die(db_error($sql));
	return $result;
}




function db_scalar($sql, $dbcon2 = null) {
	if($dbcon2==''){
		if(!isset($GLOBALS['dbconn'])) {
			
		}
		$dbcon2	= $GLOBALS['dbconn'];
	}
	$result	= db_query($sql, $dbcon2);
	if ($line =	mysqli_fetch_array($result))	{
		$response =	$line[0];
	}
	return $response;
}


function db_error($sql) {
	echo "<div style='font-family: tahoma; font-size: 11px; color: #333333'><br>";
	print_error();
	if(LOCAL_MODE) {
		echo "<br>sql: $sql";
	}
	echo "</div>";
}


function print_error() {
	$debug_backtrace = debug_backtrace();
	for ($i = 1; $i < count($debug_backtrace); $i++) {
		$error = $debug_backtrace[$i];
		echo "<br>";
		echo "<div>";
		echo "<b>File:</b> ".$error['file']."<br>";
		echo "<b>Line:</b> ".$error['line']."<br>";
		echo "<b>Function:</b> ".$error['function']."<br>";
		echo "</div>";
	}
}


function db_fetch_array($sql, $dbcon2 = null) {
	if($dbcon2==''){
		if(!isset($GLOBALS['dbconn'])) {
			
		}
		$dbcon2	= $GLOBALS['dbconn'];
	}
	$result	= mysqli_fetch_array($sql) or	die();
	return $result;
}


function db_fetch_object($sql, $dbcon2 = null) {
	if($dbcon2==''){
		if(!isset($GLOBALS['dbconn'])) {
			
		}
		$dbcon2	= $GLOBALS['dbconn'];
	}
	$result	= mysqli_fetch_object($sql) or	die();	
	return $result;
}


function NumRows($sql, $dbcon2 = null) {
	if($dbcon2==''){
		if(!isset($GLOBALS['dbconn'])) {
			
		}
		$dbcon2	= $GLOBALS['dbconn'];
	}
	$result	= mysqli_num_rows($sql) ;
	if(!is_numeric($result)){
		return 0;
	}
	else{
		return $result;
	}
}
?>