0

I am having difficulties setting attributes as explained in other related answers. Can someone help rewrite this code so that it can echo correct rows when $limi variable and $offset variable is passed.

I read related questions like set attribute , yet I could not implement it in my own to bring out something

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);
Kokwo
  • 5
  • 5
  • What does it mean, "yet I could not implement it in my own to bring out something"? – Your Common Sense Mar 30 '21 at 11:23
  • After reading through the question that are related especially the one I linked above, I couldn't solve it. In the answer, they 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. Even though that's what they recommend, since I couldn't apply it correctly, I felt I should ask the question. Did you still feel the question should be closed? – Kokwo Mar 30 '21 at 11:28
  • Yes, they do recommend exactly that – Your Common Sense Mar 30 '21 at 11:29
  • Please remove this question from close. Kindly help me open it. Where you said the answer is, I couldn't find the answer there – Kokwo Mar 30 '21 at 12:01

0 Answers0