Phalcon SQL语句参数绑定

phalcon SQL语句的参数绑定有一个坑,表名要使用::class获取才能用

然后使用

$model->getModelsManager()->executeQuery($sql, $bindArr);

正常用就可以

$goodsClass = WeGoods::class;
$snapshotClass = WeGoodsSnapshot::class;
$conditions = implode(' AND ', $where);
$sql = "SELECT g.id, g.goods_name, g.goods_intro,g.first_category,g.second_category, g.third_category, g.goods_type, g.goods_thumbnail, g.snapshot_id, g.original_goods_special, g.goods_pictures, g.original_price, g.sale_price,g.online_payment, g.store_payment, g.pay_position, g.pay_url, g.medical_department, g.company_id, g.stock_number,
 g.sale_number, g.city_id, g.original_goods_id, g.channel_id, g.online_state, g.auto_offline_time, g.offline_intro, g.offline_time, g.create_time, g.is_deleted,
 g.is_enduring, g.start_time, g.end_time
 {$addtionalCol}
 FROM {$goodsClass} as g , {$snapshotClass} as s
 WHERE g.snapshot_id = s.id AND {$conditions} 
 ORDER BY {$orderBy} 
 LIMIT {$offset},{$psize}";

// a.id as activity_id, a.category_id, a.activity_price, a.online_payment as active_online_payment, a.store_payment as active_store_payment, a.rank as active_rank,
// a.online_state as active_online_state


        $countSql = "select count(g.id) as total
 FROM {$goodsClass} as g
 WHERE {$conditions}";

        $model = new WeGoods();
        /**
         * @var \Phalcon\Mvc\Model\Resultset\Simple $re
         */
        $re = $model->getModelsManager()->executeQuery($sql, $bindArr);
        /**
         * @var \Phalcon\Mvc\Model\Resultset\Simple $total
         */
        $total = $model->getModelsManager()->executeQuery($countSql, $bindArr);

 

 

你可能感兴趣的:(PHP)