Following my code:
$list = $pdo->prepare("SELECT * FROM table_a INNER JOIN table_b ON table_a.id = table_b.blabla_id");
$list_result = $list->execute();
while($element = $list->fetch()) {
//CONTENT
}
Now I would like to fetch the columns with something like echo $element['table_a.id'];
- which doesn't work.
I don't want to write an alias for every single column. Is there a way to deal with this? :)
SOLUTION:
$list = $pdo->prepare("SELECT * FROM table_a INNER JOIN table_b ON table_a.id = table_b.blabla_id");
$list->execute();
while($element = $list->fetch(PDO::FETCH_ASSOC)) {
$a = [];
$i = 0;
foreach ( $element as $k => $v ) {
$meta = $list->getColumnMeta($i);
$a[ $meta['table'] . '.' . $k ] = $v;
$i++;
}
echo $a['table_b.blabla'];
}
As kmoser mentioned, it's possible to improve the effectivity, as it's not necessary to check the column-names every loop, as they don't change.
Thanks to everyone.