catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Unexpected data when mysql query is run #780

Closed bhullar89 closed 6 years ago

bhullar89 commented 6 years ago

I am calling below query from my table to get distinct values $data['data'] = $this->dbconn->query("SELECT DISTINCT area_name FROM actions")->fetchAll();

The $data display below data

{
  "data": [
    {
      "0": "",
      "area_name": ""
    },
    {
      "0": "101",
      "area_name": "101"
    },
    {
      "0": "Floor 3",
      "area_name": "Floor 3"
    },
    {
      "0": "Floor 1",
      "area_name": "Floor 1"
    },
    {
      "0": "Floor 4",
      "area_name": "Floor 4"
    }
  ]
}

Why are there two entries in data array??
Am i doing something wrong ? or its a bug ?
bhullar89 commented 6 years ago

Using below , resolves the issues $medoo->select('actions', ['area_name' => Medoo::raw('DISTINCT(area_name)')])

ghost commented 6 years ago

Add this to option PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,