Question

Possible Duplicate:
PHP PDO bindValue in LIMIT

I started using PDO yesterday, so I am still getting easily confused with it. I have a class Query:

class Query
{
    static function GetList($query, $binds = array())
    {
        global $DBH;
        $STH = $DBH->prepare($query);
        $STH->execute($binds);

        return $STH;
    }
}

and I am calling this with:

$result = Query::GetList("SELECT * FROM translations_missing 
                          ORDER BY translation_missing_id LIMIT ?, ?", 
                          array(0, 10));
while($row = $result->fetch())
{
    echo 'moo'; 
}

And I am not getting any results! However, if I remove the parameters and call:

$result = Query::GetList("SELECT * FROM translations_missing 
                          ORDER BY translation_missing_id LIMIT 0, 10");

I get 'moo' printed several times. I am pretty sure I am missing something minor as always, but I just cannot find what is wrong with this.

To get myself confused about this even more if I do it like this:

$result = Query::GetList("SELECT * FROM translations_missing 
                          WHERE en = ?", 
                          array("Building"));

I get 'moo' printed! I am now thinking that I am binding integers in a wrong way, but... Can someone point me out why my binding is not working?

Was it helpful?

Solution

It looks like you were right about the integer binding thing.

See: How to apply bindValue method in LIMIT clause?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top