I'm trying to have mysql return column names that will be parsed by php into an array. Consider this:
$sql = "SELECT user.id AS `user[id]`, user.name AS `user[name]`,
user_info.address AS `user[info][address]`
user_info.zip AS `user[info][zip]`
FROM user JOIN user_info ON user.id = user_info.id";
$stmt = $conn->query($sql);
$results = $stmt->fetchAll();
I want $results to look something like this:
array(
[0] => array(
[id] => 2,
[name] => 'john',
[info] => array(
[address] => '1234 Main st',
[zip] => 12345
)
)
[1] => array(
[id] => 3,
[name] => 'tom',
[info] => array(
[address] => '2811 Second Ave.',
[zip] => 98765
)
)
)
Is there any way to do this without manually looping through the results. I want functionality similar to how php handles square brackets in form submissions (ex. index.php?user[id]=2&user[name]=tom)