PDO returning incorrect, but duplicate, data. Key’s not in database.

It’s not duplicates, it’s just the current FETCH_MODE you’re using. To get as associative keys only you need to specify as such; by default it fetches as both.

Use like so:

$query->fetchAll(PDO::FETCH_NUM); // to fetch with numeric indexes
$query->fetchAll(PDO::FETCH_ASSOC); // to fetch with associative indexes

fetchAll docs
fetch docs

Leave a Comment