<?php

ini_set("error_reporting",E_ALL);
ini_set("display.errors","On");


/*$connection = mysql_connect($_cfg['db_host'],$_cfg['db_user'],$_cfg['db_pass'], TRUE)
	or die("C11 error");

$dbsel = mysql_select_db($_cfg['db_dbse'], $connection)
	or die("C21 error");

	
function dbQuery($sql, $conn="1") {
	$connect = 1
	$q = mysql_query($sql, $connect);
	
	if (!$q)
		die($sql . " - " . mysql_error($connect));
	return $q;
}

dbQuery("SET NAMES 'utf8'", "1");
function dbRes($q) {
	return mysql_fetch_assoc($q);
}
function dbNumRows($q) {
	return mysql_num_rows($q);
}
function insertID() {
	return mysql_insert_id();
}
function curDate() {
	return date("Y-m-d H:i:s");
}
function getGeneralConfig($var) {
	$gR = dbRes(dbQuery("SELECT `value` FROM settings WHERE `variable` = '".$var."'"));
	if (is_array($gR))
		return $gR['value'];
	else
		return "";
}*/

/*======*/
function connect() {
	include dirname(__FILE__) . "/_cfg.php";
	$dsn = "mysql:host=".$_cfg['db_host'].";port=3309;dbname=".$_cfg['db_dbse'];
	try {
		return new PDO($dsn, $_cfg['db_user'], $_cfg['db_pass']);
	}
	catch (PDOException $e) {
		showErrorTemplate($e->getMessage());
	}
}

function queryWithBids($sql, $bids, $error = TRUE){
	$conn =connect();

	try {
		if (empty($sql))
			throw new Exception("Query was empty");
		//priprav statement
		$stmt = $conn->prepare($sql);
		//echo 'dobra queryWi :'.$sql.'<br>';

		$i=1;
		//nabinduj premenne
		foreach ($bids as &$value){
			$stmt->bindParam( $i, $value);
			$i++;
		}
			
			
		unset($value);
			
		if (!$stmt->execute())
			throw new Exception($sql . "Databaza nespustila query <br /><br />\n\n" );
			
	} catch (Exception $e) {
		if ($error)
			showErrorTemplate("db_query",$e->getMessage());
	}
	return $stmt;
}

?>