定制 jasny/dbquery-mysql 二次开发

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

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

jasny/dbquery-mysql

最新稳定版本:v2.0.0

Composer 安装命令:

composer require jasny/dbquery-mysql

包简介

Query builder and parser for MySQL

README 文档

README

Build Status

This library is designed to be the ultimate tool for building, splitting and modifying MySQL queries.

Automatic smart quoting helps against SQL injection and problems with reserved keywords.

The query builder can be used standalone, in conjunction with Jasny's DB layer or in almost any framework.

Installation

Jasny's MySQL query builder is registred at packagist as jasny/dbquery-mysql and can be easily installed using composer.

composer install jasny/dbquery-mysql

Alternatively you can simply download the .zip and copy the file from the 'src' folder.

Examples

An example to simple to be using a query builder

use Jasny\DB\MySQL\Query;

$query = Query::select()->columns('id', 'name')->from('foo')->where('active = 1');
$result = $mysqli->query($query); // SELECT `id`, `name` FROM `foo` WHERE `active` = 1

Dynamicly apply paging and filtering on a query

use Jasny\DB\MySQL\Query;

$query = new Query("SELECT * FROM foo LEFT JOIN bar ON foo.bar_id = bar.id WHERE active = 1 LIMIT 25");
if (isset($_GET['page'])) $query->page(3);

$filter = isset($_POST['filter']) ? $_POST['filter'] : array(); // array('type' => 'bike', 'price between ? and ?' => array(10, 20))
foreach ($filter as $field => $value) {
    $query->where($field, $value);
}

$result = $mysqli->query($query); // SELECT * FROM foo LEFT JOIN bar ON foo.bar_id = bar.id WHERE (active = 1) AND (`type` = "bike") AND (`price` between 10 and 20) LIMIT 25 OFFSET 50

Map fields for an INSERT INTO ... SELECT ... ON DUPLICATE KEY query

use Jasny\DB\MySQL\Query;

$columns = array(
    'ref' => 'ref',
    'man' => 'boy',
    'woman' => 'girl',
    'amount' => 'SUM(z.bucks)'
);

$select = Query::select()->columns($columns)->from('foo')->innerJoin('z', 'foo.id = z.foo_id')->groupBy('foo.id');
$insert = Query::insert()->into('abc')->columns(array_keys($columns))->set($select)->onDuplicateKeyUpdate();

$mysql->query($insert); // INSERT INTO `abc` (`ref`, `man`, `woman`, `amount`)
                        //  SELECT `ref` AS `ref`, `boy` AS `man`, `girl` AS `woman`, SUM(`z`.`bucks`) AS `amount` FROM `foo` LEFT JOIN `z` ON `foo`.`id` = `z`.`foo_id` GROUP BY `foo`.id`
                        //  ON DUPLICATE KEY UPDATE `ref` = VALUES(`ref`), `man` = VALUES(`man`), `woman` = VALUES(`woman`), `amount` = VALUES(`amount`)

API documentation (generated)

http://jasny.github.com/dbquery-mysql/docs

统计信息

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

GitHub 信息

  • Stars: 29
  • Watchers: 7
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-11-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固