M
M
Maxim Lagoysky2019-06-03 17:10:07
symfony
Maxim Lagoysky, 2019-06-03 17:10:07

Is it possible to get data from the database in this form?

Hello everyone, there was such a question, there is a table with two columns "key", "value". The question arose, is it possible to obtain a result of this type when sampling?

array(
    'key' => 'value',
    'key' => 'value',
    'key' => 'value'
)

I know there is an index by but there, not in this form, I will still get the result, there there will be an array in place of value.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2019-06-03
@Maksclub

If I understand the problem correctly, then you need to hydrate to the desired format.
Can you indicate the type of hydration $query->getResult(Query::HYDRATE_SCALAR)?
You can also make a custom hydrator
In general, it's strange that there is an array, there should be an object, maybe Query::HYDRATE_OBJECTit's by default, you didn't set it by chance Query::HYDRATE_ARRAY, maybe the code was copied from somewhere with this value?
Delve into the Possibilities: Doctrine 2: Hydration Modes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question