host = $config['server']; $this->user = $config['user']; $this->pass = $config['pass']; $this->database = $config['database']; $this->cnx = mysql_connect($this->host,$this->user,$this->pass) or die("Cannot connect to MySQL" . mysql_error()); mysql_select_db($this->database) or die(mysql_error()); } // Select Query function selectQry($table,$condition,$limitS,$limitE) { if(!$condition){ if((!$limitS) && (!$limitE)) $sql="select * from ".$table; else $sql="select * from ".$table." limit ".$limitS.", ".$limitE; } else { if((!$limitS) && (!$limitE)) $sql="select * from ".$table." where ".$condition; else $sql="select * from ".$table." where ".$condition." limit ".$limitS.", ".$limitE; } //echo $sql; //die(); $dataSet=$this->executeQry($sql); return $dataSet; } // Select With Order By Condition////////////////////////////////////////////////// function selectOrderQry($table,$condition,$orderby,$limitS,$limitE) { if(!$condition){ if((!$limitS) && (!$limitE)) $sql="select * from ".$table." order by ".$orderby; else $sql="select * from ".$table." order by ".$orderby." limit ".$limitS.", ".$limitE; } else { if((!$limitS) && (!$limitE)) $sql="select * from ".$table." where ".$condition." order by ".$orderby; else $sql="select * from ".$table." where ".$condition." order by ".$orderby." limit ".$limitS.", ".$limitE; } //echo $sql; $dataSet=$this->executeQry($sql); return $dataSet; } /////////////////////////////////////////////////////////////////////// function editRec($table,$frmval,$condition) { $sql="update ".$table." set ".$frmval." where ".$condition; $dataSet=$this->executeQry($sql); return $dataSet; } function executeQry($sql) { if (!is_string($sql)) { //throw new Exception("Illegal parameter. Must be string."); die("Illegal parameter. Must be string."); } else { $rsSet = mysql_query($sql); } if (!$rsSet) //$this->throwMysqlException(); die(@mysql_errno()); else return $rsSet; } function insert_id() { return mysql_insert_id(); } function deleteval($tbl,$con){ $this->dbConnect(); $sql="delete from ".$tbl." where ".$con; $result=mysql_query($sql) or die(mysql_error()); } function getResultRow($DataSet) { return mysql_fetch_array($DataSet); } function getResultObject($DataSet) { return mysql_fetch_object($DataSet); } function getTotalRow($DataSet) { return mysql_num_rows($DataSet); } function addParameter($param) { $allParam=$allParam; } function throwMysqlException($addToMessage = "") { if (is_string($addToMessage)) { $message = $addToMessage ." \n". @mysql_error($this->dbConnect()); } else { $message = @mysql_error($this->dbConnect()); } //throw new Exception($message, @mysql_errno($this->dbConnect())); die(@mysql_errno($this->dbConnect())); } function fetchValue($tbl, $field, $con){ //$this->dbConnect(); $sql="select ".$field." from ".$tbl." where ".$con; $result=mysql_query($sql) or die(mysql_error()); $rows=mysql_num_rows($result); $rec=mysql_fetch_object($result); $val=$rec->$field; return $val; } function updateValue($tbl,$con,$val){ $this->dbConnect(); $sql="update ".$tbl." set ".$val." where ".$con; $result=mysql_query($sql) or die(mysql_error()); } function singleValue($tbl,$con){ $sql="select * from ".$tbl." where ".$con; $result=mysql_query($sql) or die(mysql_error()); $rec=mysql_fetch_object($result); return $rec; } function deleteRec($table,$condition) { if(!$condition){ $sql="delete from ".$table; } else{ $sql="delete from ".$table." where ".$condition; } $dataSet=$this->executeQry($sql); return $dataSet; } function cleanInput($value) { return mysql_real_escape_string($value); } // Paging Test function paging($query) { $this->offset=0; $this->page=1; $this->sql=$query; $this->rs=mysql_query($this->sql); $this->numrows=mysql_num_rows($this->rs); } function getNumRows() { return $this->numrows; } function setLimit($no) { if($no) $this->limit=$no; else $this->limit=10; } function getLimit() { return $this->limit; } function getNoOfPages() { return ceil($this->noofpage=($this->getNumRows()/$this->getLimit())); } function getPageNo() { $str=""; $str=$str.""; $str=$str.""; $str=$str."
Page : "; if($this->getPage()>1) { $str=$str."Prev  "; } if($this->getPage() > 6) { $l = 1; for($i=$this->getPage()-1;$i>0;$i--) { $arr[] = "".$i." "; if($l == 5) break; $l++; } if($this->getNoOfPages()-$this->getPage() < 5) { $start = $i -1; $diff = $this->getNoOfPages()-$this->getPage(); $loop = 5-$diff; for($m = 1; $m<=$loop; $m++) { if($start>0) $arr[] = "".$start." "; $start--; } } $arrrev = array_reverse($arr); foreach($arrrev as $val) $str = $str.$val; } $current = $this->getPage(); if($current > 6) { $k = 1; for($i=$current;$i<=$this->getNoOfPages();$i++) { if($i==$this->getPage()) { $str=$str."".$i." "; } else { $str=$str."".$i." "; } if($k == 6) break; $k++; } } else { $j = 1; for($i=1;$i<=$this->getNoOfPages();$i++) { if($i==$this->getPage()) { $str=$str."".$i." "; } else { $str=$str."".$i." "; } if($j == 8) break; $j++; } if($this->getNoOfPages() > $i+1) { $str=$str.".. "; } } if($this->getPage()<$this->getNoOfPages()) { $str=$str."Next"; } $str=$str."
"; return $str; } function getOffset($page) { if($page>$this->getNoOfPages()) { $page=$this->getNoOfPages(); } if($page=="") { $this->page=1; $page=1; } else { $this->page=$page; } if($page=="1") { $this->offset=0; return $this->offset; } else { for($i=2;$i<=$page;$i++) { $this->offset=$this->offset+$this->getLimit(); } return $this->offset; } } function getPage() { return $this->page; } function setStyle($style) { $this->style=$style; } function getStyle() { return $this->style; } function setActiveStyle($style) { $this->activestyle=$style; } function getActiveStyle() { return $this->activestyle; } function setButtonStyle($style) { $this->buttonstyle=$style; } function getButtonStyle() { return $this->buttonstyle; } function setParameter($parameter) { $this->parameter=$parameter; } function getParameter() { return $this->parameter; } function getQueryString() { $queryString_arr = explode('&',$_SERVER['QUERY_STRING']); $queryStringNew = ""; if(count($queryString_arr) > 0) { $srchString = "age="; $srchStringLimit = "imit="; foreach($queryString_arr as $queryString_arr2) { $posString = strpos($queryString_arr2,$srchString); $posStringLim = strpos($queryString_arr2,$srchStringLimit); if($posString != 1 && $queryString_arr2 != '') $queryStringNew .= "&".$queryString_arr2; } //echo $queryStringNew; exit; } /*if($_GET['limit'] != '') { $queryStringNew .= "&limit=".$_GET['limit']; }*/ return $queryStringNew; } public function errno() { return mysql_errno($this->link); } public function error() { return mysql_error($this->link); } public static function escape_string($string) { return mysql_real_escape_string($string); } public function query($query) { return mysql_query($query); } public function fetch_array($result, $array_type = MYSQL_BOTH) { return mysql_fetch_array($result, $array_type); } public function fetch_row($result) { return mysql_fetch_row($result); } public function fetch_assoc($result) { return mysql_fetch_assoc($result); } public function fetch_object($result) { return mysql_fetch_object($result); } public function num_rows($result) { return mysql_num_rows($result); } public function curPageInfo() { return substr($_SERVER["REQUEST_URI"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } } ?>