Why is there no result in PDO fetch Collum?

Asked

Viewed 91 times

1

I made a query and want to use fetch Collum according to a reply from the other site;

$query = $pdo->prepare("SELECT b.**, b.**, b.**, b.**, b.**, b.**, b.**, b.**, b.**, b.**, b.token FROM tbl_contas AS b");
    $query->execute();

$iToken = $query->fetchColumn(11);
$tokenHash = $iToken['token'];

Because it does not return the token in the variable $tokenHash?

  • if(!$query->execute()){print_r($query->errorInfo());} so shows some error?

  • No mistakes, all right

  • In your actual query you have those two asterisks followed even?

  • No, it was just to illustrate the positions @rray

1 answer

0


The problem is the column index to the total is 11 but as the documentation informs the count should start at zero.

0-Indexed number of the column you Wish to Retrieve from the Row. If no value is supplied, Pdostatement::fetchColumn() fetches the first column.

Just in your case change:

$iToken = $query->fetchColumn(11);

To:

$iToken = $query->fetchColumn(10);

Recommended reading:

Documentation - fetchColumn()

Browser other questions tagged

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