execute($RegisterDa...">

PHP PDO fetch returns an array?

$GetUid = $dbConnect->prepare("SELECT UID FROM users WHERE username = :username");
$GetUid->execute($RegisterData3);
$UserID = $GetUid->fetch();

why does it return an array not a string?

var_dump ('$ UserID') says

array
  'UID' => string '45' (length=2)
  0 => string '45' (length=2)

he should be

array
  'UID' => string '45' (length=2)

update * how about 0? where did she come from thanks for answers.

+5
source share
3 answers

You did not specify a parameter fetch_style. It returns FETCH_BOTHby default, which is an array. Here are the options and ways to specify them: http://php.net/manual/en/pdostatement.fetch.php

EDIT: , , . FETCH_ASSOC, , fetch(), , , 0.

+13

, fetchColumn() PDOStatement.

+2

The result set is displayed row by row, even if the row contains one column

+2
source

All Articles