ソースを参照

Merge pull request #22 from liujian883/master

增加SQL Order By排序方式
walkor 10 年 前
コミット
de885f9646
1 ファイル変更25 行追加1 行削除
  1. 25 1
      GatewayWorker/Lib/DbConnection.php

+ 25 - 1
GatewayWorker/Lib/DbConnection.php

@@ -86,6 +86,11 @@ class DbConnection
     protected $order_by = array();
     
     /**
+     * ORDER BY 的排序方式,默认为升序
+     * @var bool 
+     */
+    protected $order_asc = true;
+    /**
      * SELECT多少记录
      * @var int
      */
@@ -944,6 +949,17 @@ class DbConnection
     {
         return $this->addOrderBy($cols);
     }
+     /**
+     * order by ASC OR DESC
+     * @param array $cols
+     * @param bool $order_asc
+     * @return self
+     */
+    public function orderByASC(array $cols, $order_asc = true)
+    {
+        $this->order_asc = $order_asc;
+        return $this->addOrderBy($cols);
+    }
     
     // -------------abstractquery----------
     /**
@@ -1101,7 +1117,15 @@ class DbConnection
         if (! $this->order_by) {
             return ''; 
         }
-        return ' ORDER BY' . $this->indentCsv($this->order_by);
+
+        if ($this->order_asc)
+        {
+            return ' ORDER BY' . $this->indentCsv($this->order_by) . ' ASC';
+        }
+        else
+        {
+            return ' ORDER BY' . $this->indentCsv($this->order_by) . ' DESC';
+        }
     }
     
     /**