Sometimes small tricks are very handy. Mysql provides a function that creates JSON values for the row result.
mysql> SELECT JSON_OBJECT('id', 87, 'name', 'carrot');
Run query in PHP
SELECT json_object('name', name, 'phone', phone) FROM person;
Check with MySQL documentation