Consider the following mysql query: SELECT a.*, b.* FROM a INNER JOIN b ON b.id = a.b_id
. These two tables have identicaly named columns (id
for example). I was under the assumption, that if I run this query with php, I will be able to access the fields from each returned row of the query the following way:
$sql = "SELECT a.*, b.* FROM a INNER JOIN b ON b.id = a.b_id";
$result = mysqli_query($connection, $sql);
$row = mysqli_fetch_assoc($result));
print_r($row);
My expected outcome from a similar script would need to be an array along the following lines:
array(
'a.id' => ...,
'b.id' => ...,
'a.b_id' => ...
)
Instead, what I get is something like this:
array(
'id' => ...,
'b_id' => ...
)
If I run the same query in mysql, I get the results from both tables in the result set (so columns with overlaping names aren't retrieved only once). Is there any way to simulate the same thing with php, and still maintain using wildcard in the query?
I am well aware of why wildcard should not be used in queries, but taking into account, that I will need to use ALL columns from these two tables in my script, and we are talking about a bunch of columns, I would prefer to use it this way.