Total Complexity | 9 |
Total Lines | 114 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
12 | class Read |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var |
||
17 | */ |
||
18 | private $db; |
||
|
|||
19 | /** |
||
20 | * @var |
||
21 | */ |
||
22 | private $table; |
||
23 | /** |
||
24 | * @var |
||
25 | */ |
||
26 | private $read; |
||
27 | /** |
||
28 | * @var |
||
29 | */ |
||
30 | private $statement; |
||
31 | /** |
||
32 | * @var |
||
33 | */ |
||
34 | private $terms; |
||
35 | /** |
||
36 | * @var |
||
37 | */ |
||
38 | private $result; |
||
39 | |||
40 | /** |
||
41 | * @var \PDOStatement |
||
42 | */ |
||
43 | private $select; |
||
44 | |||
45 | private $query; |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Read constructor. |
||
50 | */ |
||
51 | public function __construct() |
||
52 | { |
||
53 | |||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return mixed |
||
58 | */ |
||
59 | public function getResult() |
||
60 | { |
||
61 | return $this->result; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param $table |
||
66 | * @param null $parse |
||
67 | * @return array |
||
68 | */ |
||
69 | |||
70 | public function query(string $query, string $parse = null) |
||
71 | { |
||
72 | if ($parse){ |
||
73 | parse_str($parse, $this->statement); |
||
74 | |||
75 | } |
||
76 | |||
77 | $this->query = $query; |
||
78 | $this->read = DB::connect()->prepare($this->query); |
||
79 | $this->read->execute($this->statement); |
||
80 | $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ); |
||
81 | |||
82 | |||
83 | |||
84 | } |
||
85 | |||
86 | public function all($table) |
||
87 | { |
||
88 | $this->table = (string)$table; |
||
89 | |||
90 | |||
91 | |||
92 | $this->read = DB::connect()->prepare("SELECT * FROM {$this->table}"); |
||
93 | $this->read->execute(); |
||
94 | return $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ); |
||
95 | |||
96 | |||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param string $table |
||
101 | * @param string $terms |
||
102 | * @param string $parse |
||
103 | * @return mixed |
||
104 | */ |
||
105 | public function find(string $table, string $terms, string $parse) |
||
106 | { |
||
107 | $this->table = $table; |
||
108 | $this->terms = $terms; |
||
109 | |||
110 | if ($parse) { |
||
111 | parse_str($parse, $this->statement); |
||
112 | } |
||
113 | |||
114 | try { |
||
115 | $this->read = DB::connect()->prepare("SELECT * FROM {$this->table} {$this->terms}"); |
||
116 | $this->read->execute($this->statement); |
||
117 | return $this->result = $this->read->fetchAll(\PDO::FETCH_OBJ); |
||
118 | } catch (\PDOException $e) { |
||
119 | echo $e->getMessage() . " in " . $e->getFile(); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | public function getRowCount() |
||
126 | } |
||
127 | |||
128 | |||
129 | } |