Answer the question
In order to leave comments, you need to log in
How to store arrays in a database?
There is a PHP script. An array is generated. How can I store it in a database (MySQL) so that it can be easily manipulated when it is accessed? And what if the array is made up of other arrays? I would like to see small code examples, or in extreme cases, links that can be used. Thank you.
Array example:
Array
(
[grounds] => Array
(
[1] => Array
(
[date] => 2014-05-28
[timeStart] => 8:45
[timeEnd] => 9:45
[groundId] => 1
[price] => 1500
)
[2] => Array
(
[date] => 2014-06-4
[timeStart] => 8:45
[timeEnd] => 9:45
[groundId] => 2
[price] => 1800
)
)
[count] => 2
[summ] => 3300
)
Answer the question
In order to leave comments, you need to log in
1. serialize / unserialize (for storage in the database, that's it)
2. JSON (if you need an exchange via AJAX without conversions)
I would prefer JSON serialization. Their processing time is approximately the same, but JSON arrays take up 30-40% less space.
In general, storing arrays in a database is an extremely thankless task . If you can somehow get around this, do it better, otherwise it will come out at a high cost of refactoring and optimizing the database.
Well, to make it convenient to manipulate, it is necessary to disassemble this array and write it to the database.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question