Yii不允许我在SQL查询中使用别名

时间:2016-05-23 15:36:52

标签: php sql yii yii2

以下代码返回错误:

       $orders = Yii::$app->db->createCommand("SELECT
                                            Orders.CustomerName AS BillingName
                                              FROM `Orders`
                                              WHERE `CustomerId` = :student_id ORDER BY Orders.`EntryDate` DESC")->bindValues([":student_id" => $student_id])->queryAll();
    $orders_result = [];
    $i = 0;
    foreach ($orders as $order) {
        $total_books_price = 0;
        $orders_result[$i] = [
            "BillingName" => $order["CustomerName"],

        ];

但如果我将SELECT COLUMN AS ALIAS替换为SELECT *,则可以正常使用。

0 个答案:

没有答案