OOP DB

<?php  

 class Databases{
      public $con;
      public function __construct()
      {
           $this->con = mysqli_connect("localhost", "root", "", "portal");
           if(!$this->con)
           {
                echo 'Database Connection Error ' . mysqli_connect_error($this->con);
           }
      }

      public function insert($table_name, $data)
      {
           $string = "INSERT INTO ".$table_name." (";          
           $string .= implode(",", array_keys($data)) . ') VALUES (';          
           $string .= "'" . implode("','", array_values($data)) . "')";
           if(mysqli_query($this->con, $string))
           {
                return true;
           }
           else
           {
                echo mysqli_error($this->con);
           }
      }

  public function insertsingle($name,$username,$password)
      {
           $string = "INSERT INTO academic (name,username,pw) VALUES ('$name','$username','$password')";
           $rsint=mysqli_query($this->con, $string);
  return $rsint;
      }

      public function select($table_name)
      {
           $array = array();
           $query = "SELECT * FROM ".$table_name."";
           $result = mysqli_query($this->con, $query);
           while($row = mysqli_fetch_assoc($result))
           {
                $array[] = $row;
           }
           return $array;
      }
 
  public function viewforup($id)
{
$vfu="SELECT * FROM academic WHERE id='$id' ";
$rs = mysqli_query($this->con, $vfu);
$vfurow=mysqli_fetch_array($rs);
return $vfurow;
}
 
  public function update($id,$name,$username,$password)
{
$up="UPDATE academic SET name='$name' , username='$username' , pw='$password' WHERE id='$id' ";
$uprs = mysqli_query($this->con, $up);
return $uprs;
}

  public function del($id)
{
$deldel="DELETE FROM academic WHERE id=$id";
$delrs = mysqli_query($this->con, $deldel);
return $delrs;
}

  public function login($username,$password)
{
$loginquery="SELECT * FROM academic WHERE username='$username' AND pw='$password' ";
$loginrs = mysqli_query($this->con, $loginquery);
$rows=mysqli_num_rows($loginrs);
return $rows;
}

  public function ses($user_check)
{
$sesrs="SELECT username FROM academic WHERE username='$user_check' ";
$sesquery = mysqli_query($this->con, $sesrs);
$rowrs=mysqli_fetch_assoc($sesquery);
return $rowrs;
}

  public function checkun($username)
{
$checkquery="SELECT * FROM academic WHERE username='$username' ";
$loginrs = mysqli_query($this->con, $checkquery);
$rowc=mysqli_num_rows($loginrs);
return $rowc;
}
 
  public function imgreg($fname,$username,$password,$filename,$filepath,$filetype)
   {
   $imginsert = "INSERT INTO academic (fname,username,pw,img_name,img_path,img_type) VALUES ('$fname','$username','$password','$filename','$filepath','$filetype')";
   $imgquery=mysqli_query($this->con, $imginsert);
   return $imgquery;
   }
 
 }
 ?>

0 comments:

Tweet Now !!

Recommend us on Google!