Skip to content

这是一个数据库操作类,查询构造器!

Notifications You must be signed in to change notification settings

sky8652/database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WaitMoonMan/database

Build Status Style CI License

查询构造器

<?php
     use Waitmoonman\Database\DB;
     
     require 'vendor/autoload.php';
     
     
     $config = [
                   'host' => 'localhost',
                   'database' => 'test',
                   'username' => 'root',
                   'password' => 'root',
                   'charset' => 'utf8',
               ];

     // 初始化配置  之后可以进行 CURD 了
     DB::addConnection($config);
    
    
     // 增
     $id = DB::table('users')->listenSql(
         function($sql, $params, $realSql){
             // do something
             var_dump($realSql);
         }
         , true
     )->insert(['name' => 'hello', 'email' => '[email protected]', 'password' => '123456']);
     
     // 删
     $rowNum = DB::table('users')
         ->listenSql(
             function($sql, $params, $realSql){
                 // do something
                 var_dump($realSql);
             }
             , true
         )
         ->where('id', '>' ,10)
         ->where('login_count', 0)
         ->delete();
      
     // 查 ->find(1);
     $users = DB::table('users')->find([1, 2, 3]);
     $user = DB::table('users')->where('id', '>' ,1)->first();
     $users = DB::table('users')
         ->listenSql(
                 function($sql, $params, $realSql){
                     // do something
                     var_dump($realSql);
                 }
                 , true
         )
         ->select('id', 'name', 'sex')
         ->where('id', '>' ,1)
         ->where('sex', 0)
         ->offset(1)
         ->limit(3)
         ->orderBy('id')
         ->orderBy('created_at', 'desc')
         ->get();
     
     // 改
     $rowNum = DB::table('users')
         ->where('id', '>' ,1)
         ->update(['name' => 'david']);
     
     
     // 分页
     $users = DB::table('users')
         ->select('id', 'name', 'email')
         ->where('id', '>' ,4)
         ->paginate(3);
     
     var_dump($users->data);
     echo $users->links();

About

这是一个数据库操作类,查询构造器!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages