Result PDO Search PHP Does not return a field

0

I make a sql query using PHP PDO. When checking the result of the query, the value of a field returns empty, but the field has value. Using the SQL statement directly in phpMyAdmin the result returns normal with all fields.

I've never seen that happen. Can anyone clarify?

$sql = "SELECT Id, Nome, IdTransacao FROM dados WHERE id = 1";
$busca = $pdo->prepare($sql);
$busca->execute();
$result = $busca->fetchALL(PDO::FETCH_OBJ);

var_dump($result);

returns only Id, Name. IdTranslation has value but shows nothing.

    
asked by anonymous 22.06.2016 / 21:11

1 answer

1

Before extracting ( fetchAll() ) the results of the query it is necessary to apply ( execute() ) it to the database.

In your code add these lines.

$sql = "SELECT Id, Nome, IdTransacao FROM dados WHERE id = 1";
$busca = $pdo->prepare($sql);
if(!$busca->execute()){
    print_r($busca->errorInfo());
}

$result = $busca->fetchAll(PDO::FETCH_OBJ);
var_dump($result);
    
22.06.2016 / 22:06