PHP fetchAll on JOIN

15 Views Asked by At

When I try to fetch from a query on a single table I get an associated array where Key is a name of column. But when I try to JOIN another table's columns on a query I get an array which only contains a key 'row' and a string value which looks like (value1,value2,value3,...,valueN), without column names. I need to get associated array (I use fetch(PDO::FETCH_ASSOC) for that) as an output, but I get a string

example of my query:

SELECT (item.id, item.category_id, item_category.letter, item_category.name_eng) 
FROM item
LEFT JOIN item_category ON item_category.letter = item.category_id
WHERE item.id = :id

I get this from that query:

Array
(
    [row] => (2314,"B","B","Name")
)

I would like to get:

Array
(
    [id] => 2314,
    [category_id] => "B",
    [letter] => "B",
    [name_eng] => "Name"
)

I've tried to explode an output string with ',' separator, but it's a dumb idea cuz if i got ',' in table data I split it into different array elements

How do I get an assoc array from that?

0

There are 0 best solutions below