A better way to generate this json array from MySql data with php

前端 未结 3 1923
梦毁少年i
梦毁少年i 2021-01-29 10:56

Sql fiddle for your convenience here.

I\'m taking data from a MySql table and turning it into a json array. All works well and I have the output the way I want it, but i

3条回答
  •  长发绾君心
    2021-01-29 11:27

    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    echo json_encode($row);
    

    You don't need the while loop, if you only have one row in your result.

提交回复
热议问题