How can I combine the values of two columns using fetchAll(PDO::FETCH_KEY_PAIR)

Hello,

In such query I am getting ID as key and product as value. no problem

prepare("SELECT id, urun FROM anten ")
fetchAll(PDO::FETCH_KEY_PAIR)

I want to get data from two columns to the value section

id | urun  | capi  |
5  | ofset | 120cm |

Is it possible to get an array like below from these three columns?
array(5=>"ofset 120cm");

Or do I have to create it with loop?

You would concatenate the columns in the sql query statement. See either - MySQL :: MySQL 8.0 Reference Manual :: 12.8 String Functions and Operators with a literal space as one of the arguments or MySQL :: MySQL 8.0 Reference Manual :: 12.8 String Functions and Operators with a space as the separator argument.

1 Like

Thank you very much, the following worked
I learned something more :wink:

CONCAT(urun,' ',capi)

Sponsor our Newsletter | Privacy Policy | Terms of Service