catfan / Medoo

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

Return data as object #535

Closed FarhanShares closed 6 years ago

FarhanShares commented 7 years ago

Can I return $medoo->select() or similar methods data as either object or array (array is already given in the example, so Im asking about object availability)?

Its nice to use objects to me: $person->name; $person->age;

instead of: $person['name']; $person['age'];

Also object takes less characters (2: ->) while array takes double (4: [' ']).

I do not know whether this feature already exists, I haven't used medoo yet. If it is, please put down some examples, docs or docs link here.

Other than, Im badly requesting this feature, its pretty and makes coding faster a bit.

catfan commented 7 years ago
$data = $database->select("xxx")...

$object = (object) $data;
turbopixel commented 7 years ago

https://github.com/catfan/Medoo/issues/516#issuecomment-273734786

FarhanShares commented 7 years ago

I also wasn't asking this way, rather an in-built solution.

ankush981 commented 3 years ago

@catfan For multiple results, this only converts the outermost array to object. Inside, we still have arrays within arrays within arrays . . . Perhaps it'd be better to do a json encode and then decode into objects.

sultank1 commented 1 year ago

author should provide options for this ... i have faced this issue ... since pdo usually return object ,,it should follow default pdo behaviour ....