F
F
funkydance2021-08-29 23:37:09
PHP
funkydance, 2021-08-29 23:37:09

How to get SQL query in JSON?

Good evening.

How can I get a SQL response in JSON like this?

SELECT `cat_id`,`title` FROM `product`;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Volodymyr Palamar, 2021-08-30
@funkydance

$sql = 'SELECT `cat_id`,`title` FROM `product`;';

$res = $mysqli->query($sql);
$rows = $res->fetch_all(MYSQLI_ASSOC); //ответ из базы

echo json_encode($rows); // json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question