Table-wise query using PDO

0

My seemingly simple problem has given me headaches. I have a table that contains three columns: id , idpergunta , resposta . When a reply is sent to be inserted in this table I check if it already exists:

$where = [
            1 => $resposta['idpergunta'],
            2 => '' . $resposta['resposta'] . '',
        ];    

        return count($this->db->select("SELECT idresposta FROM resposta WHERE aberta = 1 AND idpergunta = ? AND resposta = ?", $where));

The select method is implemented using PDO, as follows:

public function select($sql, $array = array(), $fetchMode = PDO::FETCH_OBJ, $class = '')
    {
        $stmt = $this->prepare($sql);
        foreach ($array as $key => $value) {
            if (is_int($value)) {
                $stmt->bindValue("$key", $value, PDO::PARAM_INT);
            } else {
                $stmt->bindValue("$key", $value);
            }
        }

        $stmt->execute();

        if ($fetchMode === PDO::FETCH_CLASS) {
            return $stmt->fetchAll($fetchMode, $class);
        } else {
            return $stmt->fetchAll($fetchMode);
        }
    }

However, as it stands, if the response text is longer than two words, it can not find it. Sometimes it works and sometimes it does not. I've tried it in many ways, but nothing solves it. Time works, time does not work. What can be causing this? I am absolutely sure the data is correct. If I do a query manually on the server the return happens normally.

    
asked by anonymous 25.01.2016 / 23:34

0 answers