tablename = !empty($this->tablename) ? $this->Extract($dataset,"tablename") : ''; // set databse table name $this->selectfields = !empty($this->selectfields) ? $this->Extract($dataset,"selectfields") : ''; // set parameters of table fields like * or specify // list of fields by comma likre fld1,fld2....so on $this->pagesize = !empty($this->pagesize) ? $this->Extract($dataset,"pagesize") : ''; if($this->pagesize == "") $this->pagesize = 10; // set the parameter of records per page $this->pageno = !empty($this->pageno) ? $this->Extract($dataset,"pageno") : ''; // set the default page $this->sortby = !empty($this->sortby) ? $this->Extract($dataset,"sortby") : ''; // set the field which u have to short $this->sorttype = !empty($this->sorttype) ? $this->Extract($dataset,"sorttype") : ''; // set the asc or desc the sort by field $this->groupby = !empty($this->groupby) ? $this->Extract($dataset,"groupby") : ''; // set the field which u have to group $this->sqlstr = ""; // set the query here $this->update_condition = !empty($this->update_condition) ? $this->Extract($dataset,"update_condition") : ''; // set the for add or edit the fields $this->getcondition = !empty($this->getcondition) ? $this->Extract($dataset,"getcondition") : ''; $this->search_condition = !empty($this->search_condition) ? $this->Extract($dataset,"search_condition") : ''; // set the fields for searching the record $this->recordcount = 0; // records per page $this->total_recordcount = 0; // total record count $this->lastinserted_id = 0; //when add record then last inserted id we get from // here $this->action = !empty($this->action) ? $this->Extract($dataset,"action") : ''; // set the action parameter for addd,edit or modify // records $this->succ_message = ""; $this->error_message = ""; $this->primary_id = !empty($this->primary_id) ? $this->Extract($dataset,"primary_id") : ''; // set the primary field name $this->primary_id_value = !empty($this->primary_id_value) ? $this->Extract($dataset,"primary_id_value") : ''; // set the primary field value $this->host = $host; // database connection p[arameter set here $this->user = $user; $this->pass = $password; $this->db = $db; $this->DbConnection(); //print_r($dataset); } //************************************************************************************************************* // Method Name : DbConnection() // // Description : function create databse connection // // Input : -- // // Output : -- // // Return : link with success or failure message // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function DbConnection() // function create databse connection { global $dbt; try { $dbt = new PDO('mysql:host='.$this->host.';dbname='.$this->db, $this->user, $this->pass); //$dbt->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'"); $dbt->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbt->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch (PDOException $e) { //return "Error!: " . $e->getMessage() . "
"; $error_msg = "Error!: " . $e->getMessage() . "
"; $this->show404($error_msg); } } //************************************************************************************************************* // Method Name :FireQuery() // // Description : function execue query and fill the recordset only for select query // // Input : -- pass query or set the class variable like e.g $this->sqlstr="select * from tbl_user"; // // Output : -- fetch the recordset // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function FireQuery() // function execue query and fill the record set only for select query { global $dbt; try { if(!empty($this->sqlstr) && $this->sqlstr!='null' && $this->sqlstr!=null) { $i=0; $this->recordset = array(); $stmt = $dbt->query($this->sqlstr); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $this->recordset[$i] = $row; $i++; } $this->recordcount = $stmt->rowCount(); } else { $this->recordset = ''; $this->recordcount = 0; } } catch(PDOException $ex) { //echo "Error: " . $ex->getMessage(); $error_msg = "Error: " . $this->sqlstr . " Message - " . $ex->getMessage(); $this->show404($error_msg); } } //************************************************************************************************************* // Method Name : ExecuteNonQuery() // // Description : function execute query only for insert , update and delete query // // Input : -- pass insert or update query or set the class variable like e.g $this->sqlstr= insert into tbl_user values('','name');,$this->sqlstr= update tbl_user set name='' where id=1 ; // // Output : -- // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function ExecuteNonQuery() // function execue query only for insert , update and delete query { global $dbt; try { $stmt = $dbt->exec($this->sqlstr); if($this->primary_id_value==0) { $this->lastinserted_id = $dbt->lastInsertId(); } $this->recordset=NULL; return true; } catch(PDOException $ex) { $this->error_message = "ERRORS OCCUR WHILE Add/Update Record: " . $this->sqlstr . " Message - " . $ex->getMessage(); $this->show404($this->error_message); return false; } } //************************************************************************************************************* // Method Name : GetNumberOfRows() // // Description : this function for only find out the total records // // Input : -- pass query or set the class variable like e.g $this->sqlstr="select * from tbl_user"; // // Output : -- set the $this->total_recordcount class variable with totlal record count // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function GetNumberOfRows() // this function for only find out the total records { global $dbt; try { $stmt = $dbt->query($this->sqlstr); return $this->total_recordcount = $stmt->rowCount(); } catch(PDOException $ex) { $this->error_message = "ERRORS OCCUR WHILE Get Number Of Rows: " . $this->sqlstr . " Message - " . $ex->getMessage(); $this->show404($this->error_message); return false; } } //************************************************************************************************************* // Method Name : Pagging() // // Description : this function for pagging to set the list of page no.s // // Input : -- inputting the total record count and pagesize // // Output : -- return the array with value of page no. // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function Pagging() // this function for pagging to set the list of page no.s { if($this->total_recordcount > 0 and $this->pagesize > 0) { for($i=1;$i<=ceil($this->total_recordcount/$this->pagesize);$i++) { $this->page_array[$i] = $i; } } } //************************************************************************************************************* // Method Name :Getrecords() // // Description : by setting the tablename,fiels,condition,and limit varaibles u got the recordset which u want // // Input : -- tablename,fiels,condition,sortby,sort type and limit // // Output : -- return the recordset of which u set the variables table,fields,condition,orderby and limit // // Return : return selected records array // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function Getrecords() // function get record or return dataset { $this->sqlstr = "select ".$this->selectfields." from ".$this->tablename. " where 1=1"; if($this->search_condition!="") { $this->sqlstr .= " and ".$this->search_condition; } if($this->getcondition!="") { $this->sqlstr .= " and ".$this->getcondition; } if(count($this->search) > 0) { $this->search_condition = ""; foreach($this->search as $key => $value) { if($value!="") $this->search_condition .= " and ".$key." like '%".$value."%'"; } $this->sqlstr .= $this->search_condition; } $this->search_condition=""; if($this->primary_id_value > 0 and $this->update_condition=="" and $this->search_condition=="") { $this->sqlstr .= " and ".$this->primary_id." = '".$this->primary_id_value."'"; } $this->GetNumberOfRows(); $this->Pagging(); if($this->groupby!="" ) { $this->sqlstr .= " group by ".$this->groupby; } if($this->sortby!="" ) { if($this->sorttype != 0) { $this->sorttype = " desc "; } else $this->sorttype = " asc "; $this->sqlstr .= " order by ".$this->sortby." ".$this->sorttype; } if($this->pageno > 0 and $this->pagesize > 0) { $this->sqlstr .= " limit ".(($this->pageno * $this->pagesize) - $this->pagesize).",".$this->pagesize; } // if($_SERVER['REMOTE_ADDR'] == '122.165.155.169') { // echo "
".$this->sqlstr."
"; // } /*$file = fopen("sqlss.txt","a+"); echo fwrite($file,$this->sqlstr."\n\n"); fclose($file);*/ unset($this->recordset); $this->FireQuery(); if($this->recordcount > 0) { return $this->recordset; } } //************************************************************************************************************* // Method Name :Getrecordsmonthly() // // Description : by setting the tablename,fiels,condition,and limit varaibles u got the recordset which u want // // Input : -- tablename,fiels,condition,sortby,sort type and limit // // Output : -- return the recordset of which u set the variables table,fields,condition,orderby and limit // // Return : return selected records array // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function Getrecordsmonthly() // function get record or return dataset { $this->sqlstr = "select ".$this->selectfields." from ".$this->tablename. " where 1=1"; if($this->search_condition!="") { $this->sqlstr .= " and ".$this->search_condition; } if($this->getcondition!="") { $this->sqlstr .= " and ".$this->getcondition; } if(count($this->search) > 0) { $this->search_condition = ""; foreach($this->search as $key => $value) { if($value!="") $this->search_condition .= " and ".$key." like '%".$value."%'"; } $this->sqlstr .= $this->search_condition; } $this->search_condition=""; if($this->primary_id_value > 0 and $this->update_condition=="" and $this->search_condition=="") { $this->sqlstr .= " and ".$this->primary_id." = '".$this->primary_id_value."'"; } $this->GetNumberOfRows(); $this->Pagging(); if($this->sortby!="" ) { if($this->sorttype != 0) { $this->sorttype = " desc "; } else $this->sorttype = " asc "; $this->sqlstr .= " order by ".$this->sortby." ".$this->sorttype; } // echo "
".$this->sqlstr."
"; unset($this->recordset); $this->FireQuery(); if($this->recordcount > 0) { return $this->recordset; } } //************************************************************************************************************* // Method Name :UpdateRecords() // // Description : function modifying database record by condition(necessary). // // Input : -- if u set the $this->primary_id_value == 0 and $this->update_condition=="" then this function insert the record in table or // if u set the $this->primary_id_value > 0 or $this->update_condition!="" then this function update the record of table // // Output : -- set the $this->succ_message witb successfully record updated or inserted in to the databse. // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function UpdateRecords() // function modifying database record by condition(necessary) for add record not required { if($this->primary_id_value == 0 && $this->update_condition=="") { //echo $this->primary_id_value; $fldstr = ""; $valstr = ""; $this->sqlstr = "insert into ".$this->tablename; foreach($this->updatefields as $key => $value) { if($value!="") { $fldstr .= $key.", "; $valstr .= "'".$value."', "; } } if(strlen($fldstr) > 0) $fldstr = trim($fldstr,", "); if(strlen($valstr) > 0) $valstr = trim($valstr,", "); if(strlen($fldstr) > 0 and strlen($valstr) > 0) $this->sqlstr .= " (".$fldstr.") values(".$valstr.")"; unset($fldstr); unset($valstr); } elseif($this->primary_id_value > 0 || $this->update_condition!="") { $updstr = ""; $this->sqlstr = "update ".$this->tablename." set "; foreach($this->updatefields as $key => $value) { if($value!="" or (string)$value == "0" ) $updstr .= $key." = '".$value."', "; } if(strlen($updstr) > 0) $updstr = trim($updstr,", "); if($this->update_condition == "") { $this->sqlstr .= $updstr." where ".$this->primary_id." = '".$this->primary_id_value."'"; } else { $this->sqlstr .= $updstr." where ".$this->update_condition; } unset($updstr); } //echo $this->sqlstr."
"; //die(); if($this->sqlstr != "") { if($this->ExecuteNonQuery()) { if($this->primary_id_value == 0 and $this->update_condition=="" ) $this->succ_message = "Record Added Successfully."; else $this->succ_message = "Record Updated Successfully."; } } // echo "
".$this->sqlstr."
"; } //************************************************************************************************************* // Method Name : DeleteRecord() // // Description : function delete record by default primary id value or by appplying condition // // Input : -- set this ( $this->primary_id_value or $this->update_condition ) variable for delete selected record // // Output : -- set the message variable with successfully deleted record // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function DeleteRecord() // function delete record by default primary id value or by appplying condition { if($this->primary_id_value > 0 and $this->primary_id!="") { $this->sqlstr = "delete from ".$this->tablename; $this->sqlstr .=" where ".$this->primary_id." = '".$this->primary_id_value."'"; } if($this->update_condition!="") { $this->sqlstr = "delete from ".$this->tablename; $this->sqlstr .=" where ".$this->update_condition; } // echo $this->sqlstr; // die(); //if($this->ExecuteNonQuery()) $this->ExecuteNonQuery(); global $dbt; $stmt = $dbt->query($this->sqlstr); if($stmt->rowCount() > 0) $this->succ_message = "Record Deleted Successfully."; } //************************************************************************************************************* // Method Name : CheckDuplicate() // // Description : function pop the value from array // // Input : -- set arry $this->duplicat for which field u do not want to duplicate this array key is field name and value is field vaue. // // Output : -- return false if duplicate value exist otherwise return true // // Return : // // Author : // // Creation Date : 02/12/2004 // // Change History : // //************************************************************************************************************* function CheckDuplicate() { if($this->duplicate) { $cond = " where 1=1"; foreach($this->duplicate as $key => $value) { $cond .= " and ".$key." = '".$value."'"; } $cond .= " and ".$this->primary_id." not in (0,".$this->primary_id_value.")"; $this->sqlstr = "select count(*) as rsc from ".$this->tablename.$cond; //echo $this->sqlstr; die(); $this->FireQuery(); //print_r($this->recordset); if($this->recordcount > 0) { if($this->recordset[0]["rsc"] > 0) { return false; } else return true; } else { return true; } } } function GetLeftJoinRecords() // function get record or return dataset { //echo "
".$this->sqlstr."
"; $this->FireQuery(); if($this->recordcount > 0) { return $this->recordset; } } /************************** New PDO variable sql queries ************************************************/ function FireFindDataQuery($sqlData){ global $dbt; try { if(!empty($this->sqlstr) && $this->sqlstr!='null' && $this->sqlstr!=null) { $i=0; $this->recordset = array(); //echo '
'; print_r($sqlData); print_r($this->sqlstr);
				$stmt = $dbt->prepare($this->sqlstr);	
				$stmt->execute($sqlData);
				
				while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
					$this->recordset[$i] = $row;
					$i++;
				}
				$this->recordcount = $stmt->rowCount();
			} else {
				$this->recordset = '';
				$this->recordcount = 0;
			}
		} catch(PDOException $ex) {
			
			//$this->show404($ex->getMessage());
			$path = (isset($_SERVER['REQUEST_URI']))? $_SERVER['REQUEST_URI'] : 'no path';
			$this->generateErrorTxt($path,$ex->getMessage());	
			echo "Error: " . $ex->getMessage();die();
		}		
	}


	function ExecuteNonDataQuery($sqlData){
		global $dbt;
		try {
			$stmt = $dbt->prepare($this->sqlstr);
			$stmt->execute($sqlData);
			if($this->primary_id_value==0)
			{
				$this->lastinserted_id = $dbt->lastInsertId();
			}
			$this->recordset=NULL;
			return true;
		} catch(PDOException $ex) {
			
			$path = (isset($_SERVER['REQUEST_URI']))? $_SERVER['REQUEST_URI'] : 'no path';
			$this->generateErrorTxt($path,$ex->getMessage());	
			echo "Error: " . $ex->getMessage();die();
			/*$this->error_message = "ERRORS OCCUR WHILE Add/Update Record: " . $ex->getMessage();
			echo "Error: " . $ex->getMessage();die();
			$this->show404($this->error_message);*/
			return false;
			
		}		
	}
	
	
	function GetNumberOfRowsData($sqlData) // this function for only find out the total records
	{
		//echo '
';print_r($sqlData);echo '
'; //echo $this->sqlstr; exit; global $dbt; try { $stmt = $dbt->prepare($this->sqlstr); $stmt->execute($sqlData); //$stmt = $dbt->query($this->sqlstr); return $this->total_recordcount = $stmt->rowCount(); } catch(PDOException $ex) { $this->error_message = "ERRORS OCCUR WHILE Add/Update Record: " . $ex->getMessage(); echo "Error: " . $ex->getMessage();die(); $this->show404($this->error_message); return false; } } function GetDataRecords($sqlData) // function get record or return dataset { $this->sqlstr = "select ".$this->selectfields." from ".$this->tablename. " where 1=1"; if($this->search_condition!="") { $this->sqlstr .= " and ".$this->search_condition; } if($this->getcondition!="") { $this->sqlstr .= " and ".$this->getcondition; } if(count($this->search) > 0) { $this->search_condition = ""; foreach($this->search as $key => $value) { if($value!="") $this->search_condition .= " and ".$key." like '%".$value."%'"; } $this->sqlstr .= $this->search_condition; } $this->search_condition=""; if($this->primary_id_value > 0 and $this->update_condition=="" and $this->search_condition=="") { $this->sqlstr .= " and ".$this->primary_id." = '".$this->primary_id_value."'"; } $this->GetNumberOfRowsData($sqlData); $this->Pagging(); if($this->sortby!="" ) { if($this->sorttype != 0) { $this->sorttype = " desc "; } else $this->sorttype = " asc "; $this->sqlstr .= " order by ".$this->sortby." ".$this->sorttype; } if($this->pageno > 0 and $this->pagesize > 0) { $this->sqlstr .= " limit ".(($this->pageno * $this->pagesize) - $this->pagesize).",".$this->pagesize; } //echo "
".$this->sqlstr."
"; unset($this->recordset); $this->FireFindDataQuery($sqlData); if($this->recordcount > 0) { return $this->recordset; } } /* show 404 page*/ function show404($error_message) { /* error save to admin/error.txt file */ /*echo $error_message; exit; $file = 'error.txt'; $current = file_get_contents($file); $current .= "\n".date('Y-m-d H:i:s')." ".$error_message."\n"; file_put_contents($file, $current);*/ /* Error maessage mail to admin */ //$dynamiclink='https://' . $_SERVER['HTTP_HOST']; $error=$error_message; $logo = dynamiclink.'/images/idonate.gif'; //$filename = "../templates/404_error.html"; $dirname = dirname(__FILE__); $dirarray = explode('library',$dirname); $filename = $dirarray[0]."templates/404_error.html"; $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); $contents = str_replace("<#logo#>",$logo,$contents); $contents = str_replace("<#error#>",$error,$contents); $contents = str_replace("<#year#>",date('Y'),$contents); require_once 'class.phpmailer.php'; $sentemailid="generaltester16@gmail.com"; $body = $contents; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); $mail->From = "admin@idonate.ie"; $mail->FromName = "idonate"; $mail->Subject = "iDonate SQL Error"; $mail->Body = $body; ini_set("sendmail_from","noreply@iFundraise.ie"); $mail->AddAddress($sentemailid); unset($objemail); unset($objuser); //$mail->Send(); /* redirect page */ /*$url = dynamiclink.'/404_error.php'; header('Location: ' . $url, true, 302);*/ } function generateErrorTxt($path='',$message=''){ $IP = (isset($_SERVER["HTTP_CF_CONNECTING_IP"]))? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"]; //if($IP == '122.165.155.169') include_once("mailCheck.php"); $filezz = fopen("library/SQLerrotTxtx.txt","a+"); fwrite($filezz,"Error Time : ".date("Y-m-d H:i:s")."\n"); fwrite($filezz,"IP : ".$IP."\n"); fwrite($filezz,"Path : ".$path."\n"); fwrite($filezz,"Message : ".$message."\n\n"); fclose($filezz); //if($IP == '122.165.155.169') sendEmailNotifyed($message,$path,$IP); $url = dynamiclink.'/500error.html'; header('Location: ' . $url, true, 302); exit; } } ?>