如何在php中编写JSON_TABLE查询?

时间:2019-01-16 11:50:58

标签: php json mysqli

我正在phpmyadmin(mysql 8.0.13)中运行此查询:

SELECT people.* FROM product, JSON_TABLE(attributes, '$.people[*]' COLUMNS (firstname VARCHAR(40) PATH '$."firstname"')) people

它按预期工作,但是当我在php中尝试相同的查询时,没有任何效果。

$result = mysqli_query($conn, "SELECT people.* FROM product, JSON_TABLE(attributes, '$.people[*]' COLUMNS (firstname VARCHAR(40) PATH '$."firstname"')) people");
while($row = mysqli_fetch_assoc($result))
    {
    $firstname = $row['firstname'];
    }

有人可以告诉我我在做什么错吗?

1 个答案:

答案 0 :(得分:2)

$result = mysqli_query($conn, "SELECT people.* FROM product, JSON_TABLE(attributes, '$.people[*]' COLUMNS (firstname VARCHAR(40) PATH '$.firstname')) people");

查询中出现语法错误。您在名字中混合了双引号和单引号。尝试上述查询,让我知道它是否有效。