webtron/database 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webtron/database

Composer 安装命令:

composer require webtron/database

包简介

SQL Query Builder

README 文档

README

Instalation using composer

{
    "require": {
        "webtron/database": "dev-master"
    }
}

Set up

use Webtron\Database\Connector\Connector as Connector;

use Webtron\Database\Query\Builder as DB;

$connector = new Connector([
	"database" => "app",
	"host"     => "localhost",
	"username" => "root",
	"password" => "root"
]);

DB::connect($connector);

Get all rows from a table

$users = DB::table("users")->get();
print_r($users);
SQL Output
SELECT * FROM users  

Using Where Clause

$users = DB::table("users")->where('username','Mark')->get();
print_r($users);
SQL Output
SELECT * FROM users WHERE username = 'Mark' 

Using nested parameter groupings

$users = DB::table("users")
			->where('username','Mark')
			->orWhere(function($query){
				$query->where('id','>',3)->where('username','LIKE',"J%");
			})
			->get(['username']);
print_r($users);
SQL Output
SELECT username FROM users WHERE username = 'Mark' OR ( id > '3' AND username LIKE 'J%' ) 

Using Subqueries

$users = DB::table("users")
			->where('username',function($query){
				$query->select(["username"])->from("list")->where("id",1);
			})
			->get(['username']);
print_r($users);
SQL Output
SELECT username FROM users WHERE username = ( SELECT username FROM list WHERE id = '1' ) 

Using Join Clause

$posts = DB::table('users')
			->join('comments',function($join){
				$join->on('users.id','=','comments.user_id')
					 ->where('users.id','>',2);
			})
			->get(['users.username','comments.body']);
print_r($posts);
SQL Output
SELECT users.username, comments.body FROM users INNER JOIN comments ON users.id = comments.user_id AND users.id > 2

Using the Model

use Webtron\Database\Model\Model;

class User extends Model {

	protected $table = 'users';
}
$users = User::all();
print_r($users);

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-05-30