1. Go to this page and download the library: Download easyswoole/mysqli library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// join。默认INNER JOIN
$builder->join('table2', 'table2.col1 = getTable.col2')->get('getTable');
$builder->join('table2', 'table2.col1 = getTable.col2', 'LEFT')->get('getTable');
// join Where
$builder->join('table2','table2.col1 = getTable.col2')->where('table2.col1', 2)->get('getTable');
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// groupBy.
$builder->groupBy('col1')->get('getTable');
$builder->where('col1',2)->groupBy('col1')->get('getTable');
// having
$builder->groupBy('col1')->having('col1')->get('getTable');
$builder->groupBy('col1')->having('col1', 1, '>')->get('whereGet');
// and having. having第4个参数默认是 `AND`,默认多having是`且`关系
$builder->groupBy('col1')->having('col1', 1, '>')->having('col2', 1, '>')->get('whereGet');
// or having. 下面两种方法效果相等
$builder->groupBy('col1')->having('col1', 1, '>')->orHaving('col2', 1, '>')->get('whereGet');
$builder->groupBy('col1')->having('col1', 1, '>')->having('col2', 1, '>', 'OR')->get('whereGet');
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// orderBy. 默认DESC
$builder->orderBy('col1', 'ASC')->get('getTable');
$builder->where('col1',2)->orderBy('col1', 'ASC')->get('getTable');
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// union. 相当于 adminTable UNION userTable
$builder->union((new QueryBuilder)->where('userName', 'user')->get('userTable'))
->where('adminUserName', 'admin')->get('adminTable');
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// update
$builder->update('updateTable', ['a' => 1]);
// limit update
$builder->update('updateTable', ['a' => 1], 5);
// where update
$builder->where('whereUpdate', 'whereValue')->update('updateTable', ['a' => 1]);
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// delete all
$builder->delete('deleteTable');
// limit delete
$builder->delete('deleteTable', 1);
// where delete
$builder->where('whereDelete', 'whereValue')->delete('deleteTable');
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// insert into
$builder->insert('insertTable', ['a' => 1, 'b' => "b"]);
// replace into
$builder->replace('replaceTable', ['a' => 1]);
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// 单一where条件子查询
// 等同于 SELECT * FROM users WHERE id in ((SELECT userId FROM products WHERE qty > 2))
$sub = $this->builder::subQuery();
$sub->where("qty", 2, ">");
$sub->get("products", null, "userId");
$builder->where("id", $sub, 'in')->get('users');
// 多where条件子查询
// 等同于 SELECT * FROM users WHERE col2 = 1 AND id in ((SELECT userId FROM products WHERE qty > 2))
$sub = $this->builder::subQuery();
$sub->where ("qty", 2, ">");
$sub->get ("products", null, "userId");
$this->builder->where('col2',1)->where ("id", $sub, 'in')->get('users');
// INSERT 包含子结果集
// 等同于 INSERT INTO products (`productName`, `userId`, `lastUpdated`) VALUES ('test product', (SELECT name FROM users WHERE id = 6 LIMIT 1), NOW())
$userIdQ = $this->builder::subQuery();
$userIdQ->where ("id", 6);
$userIdQ->getOne ("users", "name");
$data = Array (
"productName" => "test product",
"userId" => $userIdQ,
"lastUpdated" => $this->builder->now()
);
$this->builder->insert ("products", $data);
use EasySwoole\Mysqli\QueryBuilder;
$builder = new QueryBuilder();
// FOR UPDATE 排它锁。下面两个方法效果相同
$builder->setQueryOption("FOR UPDATE")->get('getTable');
$builder->selectForUpdate(true)->get('getTable');
// FOR UPDATE NOWAIT
$builder->selectForUpdate(true, 'NOWAIT')->get('getTable');
// FOR UPDATE WAIT Second
$builder->selectForUpdate(true, 'WAIT 5')->get('getTable');
// FOR UPDATE SKIP LOCKED
$builder->selectForUpdate(true, 'SKIP LOCKED')->get('getTable');
// LOCK IN SHARE MODE。共享锁
$builder->lockInShareMode()->get('getTable');
$builder->setQueryOption(['LOCK IN SHARE MODE'])->get('getTable');
// LOCK TABLES 获取表锁
$builder->lockTable('table');
// UNLOCK TABLES 释放表锁
$builder->unlockTable('table');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.