include('config.inc.php'); class Database { var $conn; var $links; var $result; public function Database() { $this->conn=mysql_connect(localhost,DB_USER,DB_PASS) or print mysql_error(); $this->links=mysql_select_db(DB_DATABASE,$this->conn) or print mysql_error(); } public function fetchall($tbl,$conditon=1) { $this->result=mysql_query("select * from $tbl where ".$conditon."") or print mysql_error(); if($this->total()>0) { while($d=mysql_fetch_array($this->result)) { $data[]=$d; } return $data; } return array(); } public function query($sql) { $this->result=mysql_query($sql) or print mysql_error(); return $this->result; } public function total() { $row=mysql_num_rows($this->result) or print mysql_error(); return $row; } public function fetch($res) { $row=mysql_fetch_assoc($res) or print mysql_error(); return $row; } public function fetchone($tbl,$cond) { $sql="select * from $tbl where ".$cond; $this->result=mysql_query($sql) or print mysql_error(); if(mysql_num_rows($this->result) >0) { $d=mysql_fetch_array($this->result); return $d; } } public function getURNumber() { $this->result=mysql_query("SELECT MAX(UR_Number) AS TT FROM user_gendetails WHERE type!='OFFLINE'"); list($reg_id)=mysql_fetch_array($this->result); $reg_id++; return $reg_id; } public function insertAndUpdate($data){ $ur_id=intval($data['ur_id']); $student_doc=$data['student_doc']; $student_title=$data['student_title']; $result=false; if($ur_id>0){ list($is_data)=mysql_fetch_array(mysql_query("SELECT COUNT(*) as tt FROM student_document WHERE ur_id=".$ur_id." AND student_title='".$student_title."' ")); if($is_data==0){ $result=$this->insert('student_document',$data); }else{ $newdata['student_doc']=$student_doc; $cond=" ur_id=".$ur_id." AND student_title='".$student_title."' "; $result=$this->update('student_document',$newdata,$cond); } } return $result; } public function insert($tbl,$data) { foreach ($data as $key => $value) $items[]="$key='".mysql_escape_string($value)."'"; $str="Insert into ".$tbl." set ".implode(',',$items); mysql_query($str)or print mysql_error(); return mysql_insert_id(); } public function update($tbl,$data,$cond) { foreach ($data as $key => $value) $items[]="$key='".mysql_escape_string($value)."'"; $str="Update ".$tbl." set ".implode(',',$items)." where ".$cond; mysql_query($str) or print mysql_error(); return mysql_affected_rows(); } public function delete($tbl,$cond) { $sqld="delete from $tbl where ".$cond; mysql_query($sqld); return mysql_affected_rows(); } public function multidel($tbl,$cond) { $sql = "DELETE FROM $tbl WHERE ".$cond; mysql_query($sql); return mysql_affected_rows(); } } /////////////////////////////////////////////////////////// function redirect($url) { header('location:'.$url); } ?>