0

Ok, look at this code:

    // Query building!
    $query_params = array();
    $query = ' ';

    if (!empty($data['estado'])) {
        $query .= 'estado = ? AND ';
        $query_params[] = $data['estado'];
    }

    if (!empty($data['ref'])) {
        $query .= 'ref LIKE "%?%" AND ';
        $query_params[] = $data['ref'];
    }

On the first if block, we append to the query 'estado = ?', and redbeans runs it just fine. However, when I do LIKE "%?%", redbean can't simply recognize the token, and this is the error I get:

Message: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens File: /home/imovelli/public_html/Components/Redbean/rb.php Line: 267

I've searched but couldn't find, is there any specific way of querying for a substring in redbeans?

Leonardo Arroyo
  • 573
  • 6
  • 16
  • 1
    show us the full query used –  Jan 29 '14 at 19:37
  • Here's the full code along with outputs. http://pastebin.com/dPdV94pC – Leonardo Arroyo Jan 29 '14 at 19:41
  • If it is anything like a normal prepare, you'd do this: `$query .= 'ref LIKE ? AND '; $query_params[] = '%'.$data['ref'].'%';`. Don't know redbean though, so I don't know if it works that way too. – Wrikken Jan 29 '14 at 19:43
  • @Wrikken that was actually the right way of doing it. Could you please post you comment as an answer? – Leonardo Arroyo Jan 29 '14 at 19:48
  • Well, if it's the same to you, and this is just about prepared statements, I'd rather close it as a duplicate of http://stackoverflow.com/questions/661160/combine-php-prepared-statments-with-like :) – Wrikken Jan 29 '14 at 19:55

0 Answers0