<?php
/* This class will be used for common data base operations such as 
 connect, add, modify, delete, find data and database
*/

	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");
			
			$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;
		
			//for kolenmess main site
		/*    
			$connect_main= mysqli_connect(DB_HOST1, DB_USER1, DB_PASS1,DB_NAME1) or die("could not connect to server main");

			$this->connectionmain = $connect_main;
			
			// Selecting the Database for use 
			$db_select_main = mysqli_select_db($this->connectionmain,DB_NAME1) or die("could not select the database"); 
		
			$this->dbmain = $db_select_main;	
		    */
		}
		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 select_query_mainconnection($sqltext,$print="")
		{
			$query = $sqltext;
			$result = ($print == "")?mysqli_query($this->connectionmain,$query):$query;
			return $result;
		
			mysqli_close($this->connectionmain);	
		
		}
		
		function update_query_mainconnection($sqltext,$print="")
		{
			$query = $sqltext;
			$result = ($print == "")?mysqli_query($this->connectionmain,$query):$query;
			return $result;
			mysqli_close($this->connectionmain);
		}
		
		
		
			function delete_query_mainconnection($sqltext,$print="")
		{
			$query = $sqltext;
			$result = ($print == "")?mysqli_query($this->connectionmain,$query):$query;
			return $result;
				mysqli_close($this->connectionmain);
		}
		
		function insert_query_mainconnection($sqltext,$print="")
		{
			$query = $sqltext;
			$result = ($print == "")?mysqli_query($this->connectionmain,$query):$query;
			return $result;
			mysqli_close($this->connectionmain);
		}
		*/
		     
		
		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)
		{
			//
		}
		
	
	}
	
?>