I have fields that have the same name in different tables that I join. For example, ticket.status , user.status and transaction.status . Currently, the request returns only status .
How can I get the name of a table so that it overlaps similar field names from being overwritten and so I can distinguish between fields.
Simply put:
$data = array($eventId); $statement = $this->db->prepare("SELECT * FROM ticket, user, transaction WHERE ticket.eventId = ? AND ticket.userId = user.userId AND ticket.transactionId = transaction.transactionId"); $statement->execute($data); $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
In my research, I found the constant PDO::ATTR_FETCH_TABLE_NAMES , which looks like it can help, but I don’t know how to implement it (I assume through $statement->setAttribute(); somehow).
I also have concerns that this will not work, as the PHP documentation mentions that it depends on the driver.
thanks
source share