Result Search PDO PHP Does not return a field

Asked

Viewed 596 times

0

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

I’ve never seen it 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. Idtransaction has value but shows nothing.

  • 1

    Without the query or code it is quite complicated to infer something.

  • 1

    Kick in the dark. ???

  • @rray put the code

1 answer

1


Before extracting (fetchAll()) the results of the consultation shall be (execute()) she in 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);
  • I forgot to put but has the execute also

  • @Lelopes hits the question code there. echo $result[0]->id comes blank?

  • No, the fields Id, Name return values, Idtransaction does not return value, and it has value in the column.

  • @lelopes what would be the value of IdTransacao ?

  • Value of Idtransacao 10069930690006BE218A

  • @lelopes puts the return of the var_dump in the comments.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.