Getting Column Name From Queryall()

Hi I am create a project using Yii framework. I am facing some problem to get the list of column name from the result set. Here is the code-

	$sql = 'SELECT 








		  INNER JOIN `customer` ON (`order`.`order_customer_id` = `customer`.`customer_id`)

		  INNER JOIN `product` ON (`order`.`order_product_id` = `product`.`product_id`)


		  `customer`.`customer_id` = 321 ORDER BY order_date DESC';





How can I get the list column name from the $orderList


Well, print_r $orderList and see what it looks like.

Try This!

foreach($orderList as $row) {

echo $row -> column; // your column name


you can loop thru your $oderList

foreach($orderList as $key=>$value) {



Thanks for the response, but in the above code $row -> column is invalid because $row does not have any attribute called "column".

Like this maybe?


But won’t work if your query returns nothing. Also if your only goal is to retrieve column names, there should be a better way.

@bennouna it does not returns an array it returns associative array other words hash or dictionary so you cant use integer indexes

@alirz23 what do you mean?


will indeed return an array which values are the names of the columns that are in the original query.

sorry dude my bad i did not see array_keys prefixed

Like this

array(5) {


  string(<img src='' class='bbc_emoticon' alt='8)' /> "order_id"


  string(10) "order_date"


  string(12) "order_status"