MOON
Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4
System: Linux vps.panamaemb.org.sg 3.10.0-1160.80.1.vz7.191.4 #1 SMP Thu Dec 15 20:31:06 MSK 2022 x86_64
User: panama (500)
PHP: 5.2.17
Disabled: NONE
Upload Files
File: /home/panama/public_html_old/include/database.php
<?
/*
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	Please do not edit this class or any variable.
	+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	
*/
	//this class manage all database queries like addnew modify delete.
	class database extends connection_camp	{
		var $conn = "";
		var $field_array = "";
		var $where = "";
		var $stmt	= "";
		
		function database()		{
			$this->connect(); //first call connect function (constractor)
		}
		
		//this is where clause
		function where($condition)		{
			$this->where = $condition;
		}
		


		function addnew($tablename)		{
			$fieldname =  array_keys($this->field_array);
			$allvalues =  array_values($this->field_array);
			$this->stmt = "insert into " . $this->setting["database"]["prefix"] . $tablename . " (" . join(",",$fieldname) . ") values('" . join("','",$allvalues) . "')";
			$this->excuteQuery(1);
		}
		
		function update($tablename,$fieldlist = "")		{
			global $class_main;
			if(strlen(trim($this->where)) > 0)			{
				if((strlen(trim($fieldlist)) > 0))				{
					$working_data = ",";
				} else	{
					$working_data = "";
				}

				while(list($key,$value) = each($this->field_array))	{
					$fieldlist .= $working_data . $key."='".$value . "' ";
					$working_data = ",";
				}

				$this->stmt = "update " . $this->setting["database"]["prefix"] . $tablename . " set $fieldlist where " . $this->where;
				
				$this->excuteQuery(0);
			} else	{
				trigger_error("Delete can only excuted if the where condition is provided",E_USER_ERROR);
			}
		}
				
		function excuteQuery($instype){
			$this->field_array = "";
			$this->row_count = 0;
			$this->id = 0;
			$this->result = mysql_query($this->stmt,$this->conn);
			if(!$this->result) { trigger_error(mysql_error() . "<br>" . $this->stmt,E_USER_ERROR); }

			if($instype == 1)	{
				$this->id = mysql_insert_id($this->conn);
			}
			return 1;
		}
		
		function myquery($query){
			$this->stmt = $query;
			$this->excuteSQL();
		}
		
		function data($fieldname,$value){

			//$this->field_array[$fieldname] = addslashes($value);
			$this->field_array[$fieldname] = trim($value);
		}		

		function delete($tablename)	{
			$table_data = explode(",",$tablename);
			for($count = 0;$count < sizeof($table_data); $count++) {
				//$data_work = split(" as ",$table_data[$count]);			
				if(strlen(trim($this->where)) > 0)		{
					$this->stmt = "delete from " . $this->setting["database"]["prefix"] . trim($table_data[$count]) . " where " . $this->where;
					$this->excuteQuery(0);
				} else	{
					trigger_error("Delete can only excuted if the where condition is provided",E_USER_ERROR);
				}
			}
		}

		function excuteSQL()	{
			$this->field_array = "";
			$this->row_count = 0;
			$this->result = mysql_query($this->stmt,$this->conn);
			if(!$this->result) { trigger_error(mysql_error() . "<br>" . $this->stmt,E_USER_ERROR); }

			$this->row_count = mysql_num_rows($this->result);

			$columns = mysql_num_fields($this->result);
			for ($count = 0; $count < $columns; $count++){
			   $this->field_array[$count][0] = mysql_field_name($this->result, $count);
			   $this->field_array[$count][2] = mysql_field_name($this->result, $count);
			}

			

			if($this->row_count > 0)	{
				$this->moveto(0);
			}
			return 1;
		}


		function selectstmt($table,$fields = "*")	{
			$table_data = explode(",",$table);
			for($count = 0;$count < sizeof($table_data);$count++)		{
				$data_work = split(" as ",$table_data[$count]);
				if(sizeof($data_work) > 1)		{
					$table_data[$count] = $this->setting["database"]["prefix"] . $data_work[0] . " as " . $data_work[1];

				}	else	{
					$table_data[$count] = $this->setting["database"]["prefix"] . $data_work[0] . " as " .$data_work[0];
				}

			} // end of the for loop

			if(strlen(trim($this->where)) > 0) { $this->stmt =  "select $fields from " . join(",",$table_data) . " where " . $this->where; } else { $this->stmt =  "select $fields from " . join(",",$table_data) . " where 1 "; }

			return $this->excuteSQL();
		}
		
		function moveto($row_num){
			if($row_num < 0 || $row_num >= $this->row_count)	{
				trigger_error("Unable to find the record no $row_num maximium no of record is " . $this->row_count,E_USER_ERROR);
			}
			
			for ($count = 0; $count < sizeof($this->field_array); $count++)	{
			   $this->{"f_" . trim($this->field_array[$count][2])} = stripslashes(mysql_result($this->result,$row_num,$this->field_array[$count][2]));

			   $this->{"f_" . trim($this->field_array[$count][2])}=str_replace('<br>','<br />',$this->{"f_" . trim($this->field_array[$count][2])});
			}
		}

		function movefirst()	{
			$this->moveto(0);
		}

		function movelast()	{
			$this->moveto(($this->row_count - 1));
		}
		
		
		
	}//end class
?>