I am having difficulties setting attributes. Can someone help rewrite this code so that it can echo correct rows when $limi variable and $offset variable is passed.
Someone recommended $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE)
. I couldn’t implement it with this my code I gave here. Therefore, I needed someone to put it in the right place and the code work.
connection class
protected function connect(){
$dsn='mysql:host='.$this->host.';dbname='.$this->dbName;
$pdo = new PDO($dsn, $this->user, $this->pwd);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
}
Another class that uses the connect method($this) of the connection class.
protected function getAlllimitedprivilege($privilege,$status,$company, $limit, $offset){
$sql="SELECT * FROM `privilege` WHERE `privilege`=? AND `status`=? AND `company`=? ORDER BY `id` DESC LIMIT ? OFFSET ?";
$stmt= $this->connect()->prepare($sql);
$stmt->execute([$privilege,$status,$company, $limit, $offset]);
$user=$stmt->fetchAll();
return $user;
}
Code where the variables are passed
$list=$usersview->showAllprivilege('Friends','APPROVED',$_SESSION['company_id'], $limit, $offset);