mahesh kalantre
mahesh kalantre

Reputation: 51

Yii2 need data in a object format

following code gives result in an array format. I need it in object format. Below is the piece of code,

$connection = Yii::$app->getDb();

$command = $connection->createCommand("SELECT * FROM `tbl_ironing_items_price` iip ".
"LEFT JOIN `tbl_ironing_items` ii ON iip.service_id = ii.id WHERE iip.customer_id =  ".$pid);

$result = $command->queryAll();

Upvotes: 0

Views: 349

Answers (2)

Ankur Soni
Ankur Soni

Reputation: 6018

Below is the code with more Yii2 way.

TblIroningItemsPrice::find()
->select('tbl_ironing_items_price.*')
->leftJoin('tbl_ironing_items', '`tbl_ironing_items_price`.`service_id` = `tbl_ironing_items`.`id`')
->where(['tbl_ironing_items_price.customer_id' => $pid])
->with('tbl_ironing_items')
->all();

Upvotes: 1

csminb
csminb

Reputation: 2382

you can set fetch mode to queryAll arguments

$result = $command->queryAll(\PDO::FETCH_CLASS);

Upvotes: 4

Related Questions