<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 1. 單條數據查詢 find() 默認返回一維數組: $m = D('user'); $where['id'] = 1; $user = $m->where($where)->find(); 查詢某一字段的值: $m = D('user'); $where['id'] = 1; $username = $m->where($where)->find('username'); //返回 username 字段的值 (字符串) ## 2. 多條數據查詢: 默認返回二維數組 $m = D('user'); $where['id >'] = 1; $user = $m->where($where)->select(); 查詢某一字段的值: $m = D('user'); $where['id >'] = 1; $username = $m->where($where)->select('username'); //返回 username 字段的值 (一維數組) ## 3. 指定返回字段 field($field) $field:數組或字符串 $field 為索引數組時返回對應數組值的字段 $field 為關聯數組時返回對應數組鍵名的字段,字段名被轉為數組鍵值(指定字段別名) $field 為字符串時將保持原樣,框架不做解析 $m = D('user'); $where['id >'] = 1; $field = ['id','username','age']; //指定只返回 id,username,age 字段 $user = $m->field($field)->where($where)->select(); **指定所返回字段的別名:** $m = D('user'); $where['id >'] = 1; $field = ['id','username'=>'name','age']; //指定 username 字段返回的別名是 name $user = $m->field($field)->where($where)->select(); **返回除了某字段之外的所有字段:** $m = D('user'); $field = ['EXCEPT'=>'username,age']; //使用 EXCEPT 排除字段 $field = ['EXCEPT'=>'username,age','code'=>'usercode']; //排除 `username`和`age` 字段 并且將`code`字段轉成 usercode $user = $m->field($field)->where($where)->select(); **使用函數** $m = D('user'); $where['id >'] = 1; $field = ['SUM(point)'=>'totalpoint']; //point 字段求和并指定返回別名是 totalpoint $user = $m->field($field)->where($where)->select(); ## 4. 設置返回數據條數 $m = D('user'); $user = $m->limit(10)->select(); $user = $m->limit(6,10)->select(); ## 5. 設置排序方式 $m = D('user'); $user = $m->order('id')->select(); //按 `id` 字段排序 $user = $m->order('id DESC')->select(); //按 `id` 字段降序排序 ## 6. 統計查詢 $m = D('user'); $user = $m->where($where)->count(); //返回符合條件的數據總數 $user = $m->sum('point'); //point 字段求和 $user = $m->max('point'); //point 字段的最大值 $user = $m->min('point'); //point 字段的最小值 $user = $m->avg('point'); //point 字段的平均值 ## 7. 數據分組 $user = $m->group('username')->select(); //按 username 字段分組 ## 8. 聚合條件 **having 條件使用方法同 where 條件,詳情請參照 where 條件** $having = ['point >'=>100]; $user = $m->group('username')->having($having)->select(); $having = ['point >'=>100,'status'=>1]; $user = $m->group('username')->having($having)->select(); ## 9. 關聯查詢 默認是 RIGHT JOIN: $m = D('user'); $where['a.id'] = 1; $join = 'group b ON a.groupid=b.groupid'; //關聯 group 表查詢 $list = $m->alias('a')->join($join)->where($where)->select(); 指定 JOIN 類型: $join = 'LEFT JOIN group b ON a.groupid=b.groupid'; //LEFT 關聯 多個 JOIN 條件: $m = D('user'); $where['a.id'] = 1; $join[] = 'LEFT JOIN group b ON a.groupid=b.groupid'; $join[] = 'LEFT JOIN cart c ON c.uid=a.id'; /*...更多JOIN;*/ $list = $m->alias('a')->join($join)->where($where)->select(); ## 10. 事務處理 begin() 開始事務 commit() 提交事務 rollback() 回滾事務 $m = D('user'); try{ $m->begin(); //開始事務處理 //....數據操作 if(!$m->commit()) throw new \Exception("提交失敗!"); //提交事務 }catch(\Exception $e){//捕獲錯誤信息 $m->rollback(); //回滾 return $e->getMessage(); } ## 11. 行鎖 find() 和 select() 操作支持鎖定數據行; 方法是 傳入第二個參數為 true 該功能只能在事務處理中有效(也就是必須在 begin() 和 commit() 方法之間才會有效) $m = D('user'); $where['id'] = 1; try{ $m->begin(); $user = $m->where($where)->find(null,true); //鎖定該行直到操作結束 if(!$user) throw new \Exception("用戶數據不存在"); $result = $m->where($where)->setField('level',1); if(!$result) throw new \Exception("設置用戶等級失敗"); if(!$m->commit()) throw new \Exception("提交失敗!"); }catch(\Exception $e){ $m->rollback(); return $e->getMessage(); }
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看