经过一些MySQL查询后,我对我的JSON进行了编码,以便在我的应用程序中使用。
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($rows);
$response->withHeader('Content-Type', 'application/json');
$response->getBody()->write($json);
return $rows;这里是我的JSON的一个例子;
{list_id : "2", list_name : "name here", list_description : "desc here"}自然导出与列名相同。与list_id类似,在mysql列名中也是相等的。
我想改变以使它更安全,有什么快速的方法来做这个,而不是手动编写回显吗?
发布于 2018-06-12 15:24:25
您可以在选择中使用列别名为结果集中的列赋予不同的名称.
SELECT list_id as ID,
list_name as Name,
list_description as Description ...https://stackoverflow.com/questions/50820593
复制相似问题