定制 dynamonet/query-builder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dynamonet/query-builder

Composer 安装命令:

composer require dynamonet/query-builder

包简介

Fluent, flexible and lightweight SQL Query Builder for PHP 7.1 (or later)

README 文档

README

Fluent and flexible SQL-query-builder, merging in the best ideas from all query-builders out there.

Quick Overview

use Dynamo\QueryBuilder\SqlQueryBuilder as Query;

$users = (new Query)
  ->select('*') // This is the default select
  ->from('users u')
  ->leftJoin('posts p',[
    'p.user_id = u.id',
    'p.trashed' => null
  ]) // translates to: LEFT JOIN posts p ON p.user_id = u.id AND p.trashed IS NULL
  ->where([
    'role' => 'ADMIN', // translates to "role = ?", where "?" will be securely replaced by the PDO layer
    "age > $minAge", // insecure! $minAge will not be prepared! However, we allow this form for convenience
    'age >' => $minAge, // better, and prepareable
    [ 'age', '<=', $maxAge ], // field-operator-value array if you prefer
    'age BETWEEN' => [ $minAge, $maxAge ], // even better
  ], false) // false "OR's" all the previous conditions. Default is true, which will "AND" all the conditions 
  ->fetchAll(); // Fetches all the results

A warning on JOINs with array conditions

Notice that in the previous example, inside the join method, the first condition is 'p.user_id = u.id' instead of the more beatiful form 'p.user_id' => 'u.id', this is because the latter would have be translated to "p.user_id = 'u.id'", matching the posts where user_id is equal to the literal string "u.id" (not what we want).

Working with PDO connections

Create a new PDO instance, and pass it to the SqlQueryBuilder constructor:

use Dynamo\QueryBuilder\SqlQueryBuilder as Query;
....
$pdo = new \PDO('mysql:dbname=mydb;host=localhost;charset=utf8', 'myuser', 'mypass');
$query = (new Query($pdo))

or better yet, set the PDO globally:

Query::setPdo($pdo);
....
$query = (new Query()) // this will use the static PDO instance.

Install

composer require dynamonet/query-builder

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固