1. Go to this page and download the library: Download tjn/mpdo 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/ */
//1.二维数组 sql:select * from `plat_user` where (actor=1 and status=0)
$pdo->table('plat_user')
->where([
['actor', '=', 1],
['status', '=', 0]
]);
//2.一维数组 sql:select * from `plat_user` where (actor=1)
$pdo->table('plat_user')
->where(['actor', '=', 1]);
//3.分开传参 sql:select * from `plat_user` where (actor=1)
$pdo->table('plat_user')
->where('actor', '=', 1);
//1. sql:select * from `plat_user` where (actor=1 or status=0)
$pdo->table('plat_user')
->whereOr([
['actor', '=', 1],
['status', '=', 0]
]);
//1.三维数组传参 sql:select * from `plat_user` where (actor in (1,2,3) and status in(0,1))
$pdo->table('plat_user')
->whereIn([
['actor', [1,2,3]],
['status', [0,1]]
]);
//2.二维数组传参 sql:select * from `plat_user` where (actor in (1,2,3))
$pdo->table('plat_user')
->whereIn(['actor', [1,2,3]]);
//2分开参数传参 sql:select * from `plat_user` where (actor in (1,2,3))
$pdo->table('plat_user')
->whereIn('actor', [1,2,3]);
//1.三维数组传参 sql:select * from `plat_user` where (actor in (1,2,3) OR status in (0,1))
$pdo->table('plat_user')
->whereIn([
['actor', [1,2,3]],
['status', [0,1]]
]);
//1.三维数组传参 sql:select * from `plat_user` where (actor not in (1,2,3) AND status not in (0,1))
$pdo->table('plat_user')
->whereNotIn([
['actor', [1,2,3]],
['status', [0,1]]
]);
//2.二维数组传参 sql:select * from `plat_user` where (actor not in (1,2,3))
$pdo->table('plat_user')
->whereNotIn(['actor', [1,2,3]]);
//3.分开参数传参 sql:select * from `plat_user` where (actor not in (1,2,3))
$pdo->table('plat_user')
->whereNotIn('actor', [1,2,3]);
//1.三维数组传参 sql:select * from `plat_user` where (actor not in (1,2,3) OR status not in (0,1))
$pdo->table('plat_user')
->whereNotInOr([
['actor', [1,2,3]],
['status', [0,1]]
]);
//1.三维数组传参 sql:select * from `plat_user` where (actor=1 and status=0)
$pdo->table('plat_user')
->whereRaw('actor=? and status=?', [1, 0]);
//1.sql:select * from `plat_user` where (actor=1 and status=0) 这里只是将组装的预处理sql用execute执行,并且返回 PDOStatement结构的数据
$pdo->table('plat_user')
->whereRaw('actor=? and status=?', [1, 0])
->get();
//1.在get()的基础上fetch取出一条数据
$pdo->table('plat_user')
->whereRaw('actor=? and status=?', [1, 0])
->first();
//1.在get()的基础上fetchAll取出全部数据
$pdo->table('plat_user')
->whereRaw('actor=? and status=?', [1, 0])
->all();
//1.sql:select count(`id`) total from `plat_user` where (actor=1 and status=0) 但是count方法会直接返回int统计数
$pdo->table('plat_user')
->whereRaw('actor=? and status=?', [1, 0])
->count();
//1.sql:select * from `plat_user` where (status=0) group by actor
$pdo->table('plat_user')
->where('status', 0)
->groupBy('actor')
->all();
//1.sql:select * from `plat_user` where (status=0) order by id desc
$pdo->table('plat_user')
->where('status', 0)
->orderBy('id desc')
->all();
$pdo->table('plat_user', 'u')
->join('plat_config_detail as p', 'u.id=p.upUser')
->join('plat_actor as m', 'm.id=u.actor', 'LEFT')
->limit(0, 20)
->field('u.id, u.account, p.upUser, p.configId, u.actor, m.name as actor_name')
->all();