-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimplePDOQueryBuilderExpr.php
More file actions
50 lines (47 loc) · 1.08 KB
/
SimplePDOQueryBuilderExpr.php
File metadata and controls
50 lines (47 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Created by PhpStorm.
* User: vasiliy
* Date: 4/29/15
* Time: 11:28 AM
*/
namespace Megawilddaddy\SimplePDOQueryBuilder;
/**
* Class SimplePDOQueryBuilderExpr
* @package Megawilddaddy\SimplePdoQueryBuilder
*/
class SimplePDOQueryBuilderExpr
{
/**
* @param $field
* @param $list
* @param bool $quote
* @return string
*/
public function in($field, $list, $quote = true)
{
if (!is_array($list)) {
$list = explode(',', $list);
}
if ($quote) {
$list = array_map(function($el) {return " '$el' ";}, $list);
}
return "$field IN (" . implode(',', $list) . ")";
}
/**
* @param $field
* @param $list
* @param bool $quote
* @return string
*/
public function notIn($field, $list, $quote = true)
{
if (!is_array($list)) {
$list = explode(',', $list);
}
if ($quote) {
$list = array_map(function($el) {return " '$el' ";}, $list);
}
return "$field NOT IN (" . implode(',', $list) . ")";
}
}