2

I have a column in a mysql DB with this json content:

{"section2":"303","section1":"302","section0":"301"}

I use Medoo library. How can I search section1, section2, section3 in DB?

$database->select('Article', "*",[
                            "AND" => [
                            "section" => ?
                            ]
                       ])

                   )
Ikbel
  • 7,721
  • 3
  • 34
  • 45
elize
  • 435
  • 1
  • 8
  • 19

2 Answers2

1

Cant you just do this?

$database->select('Article', "*",[
    'section' => json_encode([
                  'section0' => 301,
                  'section1' => 302,
                  'section2' => 303
                 ])
]);

Unless of course, your trying to check for only one section. Then, no, I dont see how its possible using just sql.

Andrew
  • 300
  • 2
  • 9
0

Just search the string using like condition matching the JSON format value:

$database->select('Article', '*', [
    "section[~]" => [
        '"section1":"302"',
        '"section2":"303"',
        '"section3":"304"'
    ]
]);
Angolao
  • 986
  • 1
  • 15
  • 27