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

前端 未结 3 1893
梦毁少年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:30

    You only select needed fields, so you can just do

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

    EDIT: You mention now that name is unique, so above is all you need.

提交回复
热议问题