catfan / Medoo

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

query("SELECT ...")->fetchAll() returns rows twice #139

Closed Strosch closed 9 years ago

Strosch commented 10 years ago

Hi guys!

First off: Awesome lil framework you've got there! :-)

Unfortunately I don't know if this bug was already reported so here it is: Running a complicated SELECT query via $database->query() and then doing fetchAll() returns all rows twice.

Something like that:

row: id val: 357
row: data val: 'foobar'

would give the following array:

array('id' => 357, 0 => 357, 'data' => 'foobar', 1 => 'foobar')

Any ideas on this?

cheers, P

catfan commented 10 years ago

That is not a bug. http://php.net/manual/en/pdostatement.fetchall.php

carlosmellado commented 10 years ago

You have to write PDO::FETCH_ASSOC like a parameter inside fetchAll() function ;)

$database->query("SELECT * FROM EMPLE")->fetchAll(PDO::FETCH_ASSOC);

BurakBoz commented 5 years ago

use PDO::ATTR_DEFAULT_FETCH_MODE on connection.

new Medoo([
                'database_type' => 'mysql',
                'charset'       => 'utf8mb4',
                'collation'     => 'utf8mb4_general_ci',
                'option'        => [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
            ]);