2
I have a query, where this query works perfectly in mysql Workbench, but in php does not work.
$dados = explode("-",$ids);
$sql = "SELECT 
                    prt_produto_item.nome as nome_item,
                    prt_produto_item.qtd_referencia as qtd_referencia,
                    prt_produto_item.valor_referencia as valor_referencia,
                    prt_produto_item.valor_unitario as valor_unitario
                    FROM prt_produto_item_modulo_tipo
                    JOIN prt_produto_item ON prt_produto_item_modulo_tipo._id_produto_item = prt_produto_item.id_produto_item 
                    JOIN prt_produto_tipo_licenciamento ON prt_produto_item_modulo_tipo._id_tipo_licenciamento = prt_produto_tipo_licenciamento.id_tipo_licenciamento 
                    WHERE prt_produto_tipo_licenciamento.nome = '".$dados[1]."' AND prt_produto_item.nome = '".$dados[0]."';";
            $stmt = DB::prepare($sql);
            echo $stmt->execute();
               print_r( $stmt->fetchAll());
It runs cute, but it gives me back an empty array.
When I take prt_product.item name = $data[0] it works fine in php.
Note: the $data = explodes ("-",$ids); it’s coming perfectly
Change - echo sql result
SELECT 
                    prt_produto_item.nome as nome_item,
                    prt_produto_item.qtd_referencia as qtd_referencia,
                    prt_produto_item.valor_referencia as valor_referencia,
                    prt_produto_item.valor_unitario as valor_unitario
                    FROM prt_produto_item_modulo_tipo
                    JOIN prt_produto_item ON prt_produto_item_modulo_tipo._id_produto_item = prt_produto_item.id_produto_item 
                    JOIN prt_produto_tipo_licenciamento ON prt_produto_item_modulo_tipo._id_tipo_licenciamento = prt_produto_tipo_licenciamento.id_tipo_licenciamento 
                    WHERE prt_produto_tipo_licenciamento.nome = 'Comercial' AND prt_produto_item.nome = 'Até';
The return of the same query, in sql

my class DB
class DB{
    private static $instance;
    public static function getInstance()
    {
        if(!isset(self::$instance))
        {
            try
            {
                self::$instance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME , DB_USER, DB_PASS) ;
                //self::$instance->exec("set names utf8");
                self::$instance->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                self::$instance->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
            } catch (PDOException $e)
            {
                echo $e->getMessage();
            }
        }
        return self::$instance;
    }
    public static function prepare($sql){
        return self::getInstance()->prepare($sql);
    }
}
						
See if there are any errors:
if(!$stmt->execute()){ print_r($stmt->errorInfo());}. In the worst case the Ncode may be wrong there chews that accent.– rray
You didn’t make no mistake, man
– gabrielfalieri
He just can’t find anything
– gabrielfalieri
Ask the class implementation question
DB.– Woss
have already put....
– gabrielfalieri
And the return of
$stmt->execute()isFalse?– Woss
no, ta come true, just returning me empty, as if I had not found, but when run this same query in the database manager works perfectly
– gabrielfalieri
Have you tested with any word other than
Até, who doesn’t have accents?– Woss
No, the problem I need you to be exactly that word
– gabrielfalieri
But I’ll try it with other words, see if you find
– gabrielfalieri
Try: AND prt_producto_item.name = '". utf8_encode($data[0])."';";
– Diego Schmidt
I already tested to see if I was giving the accent, is not, come straight :(
– gabrielfalieri
Man, I put utf_decode... it worked
– gabrielfalieri
Show... if you do not want to use utf8_encode at all, put the application and database with the same encoding or add the following parameter to the PDO: $this->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
– Diego Schmidt
All right, then I’m gonna do a standardized system again, so I guess that’s the only time you blew the accent
– gabrielfalieri