Why does PDO add [0] => 1 to the fetched array?

I’m running a COUNT() on the database. Just trying to understand why PDO adds [0]=>1 to the return array.

$sql = "SELECT COUNT(`user_id`) AS `user_exists`
					FROM `users`
					WHERE `user_username` = :username";

			$stmt = $this->conn->prepare($sql);


			$test = $stmt->fetch();

When I run print_r($test) I get:

    [valid_user] => 1
    [0] => 1

Why is [0]=>1 there?


By default, pdo returns duplicate data for all queries. It returns a keyed list (the valid_user) as well as an indexed list (the 0). Set the default fetch mode when you create your connection object.

$conn = new PDO(...);