<?php
#error_reporting (E_ALL ^ E_NOTICE);
#error_reporting(E_ERROR | E_PARSE);
if(!defined("root")){define("root",$_SERVER['DOCUMENT_ROOT']);}

if (!function_exists("islocal")) {
	function islocal() {
		$http_hosts = array("localhost", "bbnew.localhost", "192.168.1.2", "192.168.1.3", "192.168.1.4", "192.168.1.5", "192.168.1.6", "192.168.1.7", "192.168.1.8", "192.168.1.9");
		if (in_array($_SERVER["HTTP_HOST"], $http_hosts)) {
			return true;
		} else {
			return false;
		}
	}
}
if (!function_exists("cvdb")) {
	function cvdb () {
		if (islocal()) {
			$DBSource = "localhost";
			$DBSource = "127.0.0.1";
			$UIDDB = "root";
			$UPWDDB = "";
			$DBName = "bolabom";
		} else {
			$DBSource = "localhost";
			$DBSource = "127.0.0.1";
			$UIDDB = "bolabom_bolabom";
			$UPWDDB = "uEtpghq3RFO7";
			$DBName = "bolabom_bolabom";
		}
		return array("dbs"=>$DBSource, "dbu"=>$UIDDB, "dbp"=>$UPWDDB, "dbn"=>$DBName);
	}
}
if (!function_exists("cvdb_log")) {
	function cvdb_log () {
		if (islocal()) {
			$DBSource = "localhost";
			$DBSource = "127.0.0.1";
			$UIDDB = "root";
			$UPWDDB = "";
			$DBName = "bolabom_log";
		} else {
			$DBSource = "localhost";
			$DBSource = "127.0.0.1";
			$UIDDB = "bolabom_bolabom";
			$UPWDDB = "uEtpghq3RFO7";
			$DBName = "bolabom_bolabom_log";
		}
		return array("dbs"=>$DBSource, "dbu"=>$UIDDB, "dbp"=>$UPWDDB, "dbn"=>$DBName);
	}
}
if (!function_exists("conn")) {
	function conn() {
		$setup = cvdb();
		$host = $setup["dbs"];
		$db   = $setup["dbn"];
		$user = $setup["dbu"];
		$pass = $setup["dbp"];
		$charset = 'utf8';
		$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
		$opt = array(
			PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
			PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
			PDO::ATTR_EMULATE_PREPARES   => false,
		);
		/*
		$opt = [
			PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
			PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
			PDO::ATTR_EMULATE_PREPARES   => false,
		];
		*/
		$pdo = new PDO($dsn, $user, $pass, $opt);
		return $pdo;
	}
}
if (!function_exists("connL")) {
	function connL() {
		$setup = cvdb_log();
		$host = $setup["dbs"];
		$db   = $setup["dbn"];
		$user = $setup["dbu"];
		$pass = $setup["dbp"];
		$charset = 'utf8';
		$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
		$opt = array(
			PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
			PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
			PDO::ATTR_EMULATE_PREPARES   => false,
		);
		/*
		$opt = [
			PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
			PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
			PDO::ATTR_EMULATE_PREPARES   => false,
		];
		*/
		$pdoL = new PDO($dsn, $user, $pass, $opt);
		return $pdoL;
	}
}
if (!function_exists("callRS")) {
	function callRS($query, array $param = NULL) {
		$pdo = conn();
		if (!isset($param)) {
			$stmt = $pdo->query($query);
			#$row = $stmt->fetch(PDO::FETCH_LAZY);
			$data = $stmt->fetchAll();
		} else {
			$stmt  = $pdo->prepare($query);
			$stmt->execute($param);
			$data = $stmt->fetchAll();
		}
		return $data;
	}
}
if (!function_exists("getID")) {
	function getID($tablename, $fieldname) {
		$rsGetID = callRS("SELECT MAX($fieldname) AS fieldID FROM $tablename");
		$getID=(count($rsGetID)!=0 && $rsGetID[0]['fieldID']!=null) ?(intval($rsGetID[0]['fieldID'])+1):1;
		return $getID;
	}
}
/*Begin Log*/
if (!function_exists("callRSL")) {
	function callRSL($query, array $param = NULL) {
		$pdoL = connL();
		if (!isset($param)) {
			$stmt = $pdoL->query($query);
			#$row = $stmt->fetch(PDO::FETCH_LAZY);
			$data = $stmt->fetchAll();
		} else {
			$stmt  = $pdoL->prepare($query);
			$stmt->execute($param);
			$data = $stmt->fetchAll();
		}
		return $data;
	}
}
if (!function_exists("getIDL")) {
	function getIDL($tablename, $fieldname) {
		$rsGetID = callRSL("SELECT MAX($fieldname) AS fieldID FROM $tablename");
		$getID=(count($rsGetID)!=0 && $rsGetID[0]['fieldID']!=null) ?($rsGetID[0]['fieldID']+1):1;
		return $getID;
	}
}
/*End Log*/
?>