D
D
Dmitry2014-05-27 11:39:43
PHP
Dmitry, 2014-05-27 11:39:43

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

4 answer(s)
A
Alexey Kuleshov, 2014-05-27
@another_dream

1. serialize / unserialize (for storage in the database, that's it)
2. JSON (if you need an exchange via AJAX without conversions)

C
cmx, 2014-05-27
@cmx

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.

1
1001001 111, 2014-05-27
@IgorO2

Well, to make it convenient to manipulate, it is necessary to disassemble this array and write it to the database.

K
KOLANICH, 2014-05-27
@KOLANICH

by line per element
but in general, you need to look towards document-oriented, in particular towards mongo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question