<?php


class dboperations
{
	var $connection;
	var $db;

	// constructor
	function __construct() {}

	function dbconnect()
	{
		global $G_userid;
		$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME) or die("could not connect to server1");
        mysqli_set_charset($connect, "utf8mb4");
		
		$this->connection = $connect;

		// Selecting the Database for use 
		$db_select = mysqli_select_db($this->connection, DB_NAME) or die("could not select the database");

		$this->db = $db_select;

	}
	function dbdisconnect() {}
	function select_query($sqltext, $print = "")
	{
		$query = $sqltext;
		$result = ($print == "") ? mysqli_query($this->connection, $query) : $query;
		return $result;
		mysqli_close($this->connection);
	}
	function insert_query($sqltext, $print = "")
	{
		$query = $sqltext;
		$result = ($print == "") ? mysqli_query($this->connection, $query) : $query;
		return $result;
		mysqli_close($this->connection);
	}
	function update_query($sqltext, $print = "")
	{
		$query = $sqltext;
		$result = ($print == "") ? mysqli_query($this->connection, $query) : $query;
		return $result;
		mysqli_close($this->connection);
	}
	function delete_query($sqltext, $print = "")
	{
		$query = $sqltext;
		$result = ($print == "") ? mysqli_query($this->connection, $query) : $query;
		return $result;
		mysqli_close($this->connection);
	}


	function numRows($result)
	{
		$rows = @mysqli_num_rows($result);
		if ($rows === null) {
			return $this->mysqliRaiseError();
		}
		return $rows;
	}

	function lookupdata_add($got_array)
	{
		$date = date("Y-m-d : h:i:sa");
		$got_array['entered_by'] = $this->userid;
		$got_array['entry_date'] = $date;

		return $got_array;
	}
	function lookupdata_edit($got_array)
	{
		$date = date("Y-m-d : h:i:sa");
		$got_array['last_edited_by'] = $this->userid;
		$got_array['last_edit_date'] = $date;

		return $got_array;
	}

	function mysqliRaiseError($errno = null)
	{
		//
	}
}
