Blank Query

1

I'm starting in the programming world and start with a problem when I run the query locally the query shows me the return normally but when I try to query through a simple application:

<?php
/**
 * 
 * @var string $dsn  : driver de conexão : endereco do servidor : nome do banco
 * @var string $user : usuario do banco
 * @var string $pass : senha do usuario 
 */
$dsn = 'odbc:driver={SQL Server};server=IP_DO_SERVIDOR;database=TESTE';
$user = 'xxxxxxx';
$pass = 'xxxxxxx';

try 
{
    $pdo = new PDO($dsn,$user,$pass);
}
catch(PDOException $exeption)
{
   die("Erro: $exeption");
}

// Definindo o mode de erros da classe
//$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$select = "SELECT * FROM FIN_TITULO WHERE EMPRESA = 1 AND REVENDA = 1 AND TITULO = 435376";

$result = $pdo->exec($select);

var_dump($result);

    
asked by anonymous 22.03.2018 / 14:54

1 answer

0

Try this:

$result = $pdo->query($select);

or

$select = "SELECT * FROM FIN_TITULO WHERE EMPRESA = 1 AND REVENDA = 1 AND TITULO = 435376";
$statement = $pdo->prepare($select);
$statement->execute();

// Verifica e gera array assoc
if($statement->rowCount()) {
    $stt = $statement->fetch(PDO::FETCH_ASSOC);
    print_r($stt);
}
  

Oops it worked, I just do not understand why the result of my query   initial had no return - Guilherme Arantes

When using PDO::EXEC the returned result is not a PDOStatement , but an integer of the affected rows.

When using PDO::QUERY the result returned is a PDOStatement .

Sources: 1 2

    
22.03.2018 / 15:00