.

.

PDO Query

Count Number Of rows

 public function getUser($username,$pwd,$usertype)
 {
  $query=$this->db->prepare("SELECT count(user_id) FROM user WHERE user_name =? and pwd = ? and user_type =? ");
  $query->bindValue(1,trim($username));
  $query->bindValue(2,trim($pwd));
  $query->bindValue(3,trim($usertype));
  
  
  try
  {
   $query->execute();
   $getrows=$query->fetchColumn();
   if($getrows>0)
   {
    return true;
   }
   else
   {
    return false;
   }
   
  }
  catch(PDOException $e)
  {
   echo $e->getMessage();
  }
 }




INSERT QUERY IN PDO

public function addUser($username,$pwd,$usertype,$address,$contact)
 {
   $query=$this->db->prepare("INSERT INTO `user` (`user_name`, `pwd`, `user_type`, `address`, `contact`) VALUES (:user_name,:pwd,:usertype,:address,:contact)");
   $query->bindValue(':user_name',trim($username));
    $query->bindValue(':pwd',trim($pwd));
$query->bindValue(':usertype',trim($usertype));
$query->bindValue(':address',trim($address));
$query->bindValue(':contact',trim($contact));
$query->execute();

 }
 FETCH  DATA AND SELECT QUERY


 public function getUserDetails($usertype)
 {
 $query=$this->db->prepare("select * from user WHERE `user_type` = ? ");
  $query->bindValue(1,trim($usertype));
  
 try
  {
   $query->execute();
   return $query->fetchAll();
   
  }
  catch(PDOException $e)
  {
   echo $e->getMessage();
  }
  return $query;

 }
UPDATE QUERY

 public function editPassword($newpwd,$usertype)
 {
 $query = $this->db->prepare("Update user set `pwd` =? WHERE `user_type` = ?");
 $query->bindValue(1,trim($newpwd));
 $query->bindValue(2,trim($usertype));
 $query->execute();

 }


EmoticonEmoticon