-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathQueryBuilder.php
More file actions
56 lines (41 loc) · 1.07 KB
/
Copy pathQueryBuilder.php
File metadata and controls
56 lines (41 loc) · 1.07 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
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace App\Structural\FluentInterface;
class QueryBuilder
{
private string $query = "";
public function select(array $fields = []): static
{
$this->query .= sprintf("SELECT %s ", sizeof($fields) ? implode(", ", $fields) : "*");
return $this;
}
public function from(string $tableName): static
{
$this->query .= " FROM {$tableName} ";
return $this;
}
public function where(array $conditions): static
{
$this->query .= sprintf("WHERE %s ", implode(" AND ", $conditions));
return $this;
}
public function offset(int $offset): static
{
$this->query .= "OFFSET {$offset} ";
return $this;
}
public function limit(int $limit): static
{
$this->query .= "LIMIT {$limit} ";
return $this;
}
public function orderBy(string $orderRule): static
{
$this->query .= "ORDER BY {$orderRule} ";
return $this;
}
public function getQuery(): string
{
return $this->query;
}
}