<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                --- ## 1. laravel 的數據庫如何創建 > 說最基本的創建命令 文件會在 databases 下面 php artisan make:migration create_order_table ## 2. laravel 創建 seed php artisan make:seed UserSeeder > 然后我們需要寫入 sedd 寫入到數據庫中 seed 目錄下面面的文件 public function run() { \Illuminate\Support\Facades\DB::table('users')->insert([ 'name' => 'white', 'email' => '986247535@qq.com', 'password' => '123456', 'created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), ]); } ## 3. laravel 三種數據庫操作 ### 3.1 直接使用原生 SQL $user = DB::select('select * from users'); $users = DB::select('select * from users where id = ?', [1]); $users2 = DB::select('select * from users where id = :id', ['id' => 1]); $insert = DB::select('insert into users(name, password, email) value (?, ? ,?)', ['zj', '123', 'zj@168.com']); $update = DB::select('update users set name = ?, email = ? , password = ? where id = ?', ['aa','122@qq.com', '123456', 2]); $delete = DB::select('delete from users where id = ?' ,[2]); ### 3.2 使用 laravel 查詢構造器 //查詢構造器 $getUser = DB::table('users')->where('id', 1)->get(); //返回的是一個 collection 集合 $findUser = DB::table('users')->find(1); //取出某一條,用ID獲取單個對象 $insertUser = DB::table('users')->insert(['name' => 'zj', 'password' => '123', 'email' => '1234@qq.com']); $firstUser = DB::table('users')->where('id', 1)->first(); //返回第一條數據,第一個對象 $valueUser = DB::table('users')->value('name'); //取到某一個 value 值 $pluckUser = DB::table('users')->pluck('name')->toArray(); // 取到某一列,并返回數據 $pageUser = DB::table('users')->paginate(2); //返回分頁 > 注意在分頁中的數據說明: #total: 3 //全部有多少個 #lastPage: 2 //最后一頁總共幾頁 #items: Illuminate\Support\Collection {#285 ?} //當前頁列表數據拿到多少個 #perPage: 2 // 一頁多少個 #currentPage: 1 //當前路徑 #path: "http://laravel.test/home/dbTest" //當前頁路徑 #query: [] //查詢的參數 #fragment: null //URL錨點 #pageName: "page" //參數名 +onEachSide: 3 //左右兩邊各顯示多少個 #options: array:2 [▼ "path" => "http://laravel.test/home/dbTest" "pageName" => "page" ] > 另外一種查詢分頁的效果 `適用與查詢非常慢的表例如幾十萬的上百萬的數據下可以用 simple` $simplePageUser = DB::table('users')->simplePaginate(2); > 兩個分頁之間的區別: 在simplePaginate 中沒有 total ,多了一個 `hasMore` 用來確認是否有下一頁 --- > #### 查詢構造器的統計方法 //統計數學方法 $maxUser = DB::table('users')->max('id'); $minUser = DB::table('users')->min('id'); $avgUser = DB::table('users')->avg('id'); $countUser = DB::table('users')->count('id'); $sumUser = DB::table('users')->sum('id'); $existsUser = DB::table('users')->where('id',1)->exists('id'); --- > ### 查詢構造器的 `where` 用法 $dumpUser = DB::table('users')->where('id', '>' ,1)->dump(); //打印SQL > 注意: 操作符可以是 `>` `<` `>=` `<=` `<>` `!=` --- > 另外 `like` 的用法 $likeUser = DB::table('users')->where('name', 'like' ,'w%')->dump(); //打印SQL $orUser = DB::table('users')->where('id', '>', 1)->orWhere('name', 'like', 'z%')->dump(); //打印SQL > #### 復制查詢 where (使用閉包來查詢) Builder > 有時候我們需要查詢復雜的語句例如下面的這句sql select * from users where id > 1 and (name like 'zj' or email like 'z%'); $complexWhereUser = DB::table('users')->where('id', '>', 1)->where(function (Builder $query){ $query->where('email', 'like', '123@%') ->orWhere('name', 'like', 'z%'); })->dump(); --- DB::table('users')->whereIn('id', [1,2])->dump(); DB::table('users')->whereNotIn('id', [1,2])->dump(); DB::table('users')->whereNotNull('id', [1,2])->dump(); DB::table('users')->whereColumn('name', 'email')->dump(); //一列的比較 > #### 其他 DML 操作 `insert` `update` insert() insertOrIgnore() //忽略插入錯誤,例如主鍵沖突 insertGetId() //新增后拿到ID Hash:make('123') //加密hash --- update() updateOrInsert() //當數據不存在就插入否則更新這條數據 ### 3.3 使用 ORM
                  <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>

                              哎呀哎呀视频在线观看