0
$query = $db->prepare("SELECT * FROM coupons WHERE deleted = ? LIMIT ?, ?");
$query->bindValue("1", 0);
$query->bindValue("2", 2);
$query->bindValue("3", 5);
    try{
        $query->execute();
        $result = $query->fetchAll();
        return $result;
    }catch(PDOException $e){
        die($e->getMessage());
}

Unfortunately this returns a result with no rows (but an empty result not even an error), and when I run this sql query through phpmyadmin, it fetches me multiple rows. Any suggestions would be really be helpful. I can't get through this.

Gaurav
  • 29
  • 9

3 Answers3

0

First comment to this question helped me very well: Here

And solved my problem. Al the above suggestions mentioned above were previously tried and did not work.

Community
  • 1
  • 1
Gaurav
  • 29
  • 9
-1

bindValue expects an integer in case of you using a question mark as a binder and not a string like you provided:

$query = $db->prepare("SELECT * FROM coupons WHERE deleted = ? LIMIT ?, ?");
$query->bindValue(1, 0);
$query->bindValue(2, 2);
$query->bindValue(2, 5);
    try{
        $query->execute();
        $result = $query->fetchAll();
        return $result;
    }catch(PDOException $e){
        die($e->getMessage());
}

or simply do this:

$query = $db->prepare("SELECT * FROM coupons WHERE deleted = ? LIMIT ?, ?");
$binds = array(0,2,5);
    try{
        $query->execute($binds);
        $result = $query->fetchAll();
        return $result;
    }catch(PDOException $e){
        die($e->getMessage());
}
Fadey
  • 430
  • 2
  • 11
-1

try to use like this

<?php
$query = $db->prepare("SELECT * FROM coupons WHERE deleted = :deleted LIMIT :limit, :offset");
$query->bindValue(":deleted", 0);
$query->bindValue(":limit", 2);
$query->bindValue(":offset", 5);
    try{
        $query->execute();
        $result = $query->fetchAll();
        return $result;
    }catch(PDOException $e){
        die($e->getMessage());
}
?>
shivanshu patel
  • 782
  • 10
  • 19