1
1
<?php
2
+
2
3
namespace DinoDev \MySql \Classes ;
4
+
3
5
use DinoDev \MySql \Classes \MySql ;
4
6
5
7
class Select extends MySql
@@ -11,28 +13,37 @@ public function __construct(MySql $_MySql)
11
13
$ this ->MySql = $ _MySql ;
12
14
}
13
15
14
- public function All (string $ table )
16
+ public function All (string $ table, int $ limit = null )
15
17
{
16
- return $ this ->MySql ->queryAndFetch ("SELECT * FROM $ table " );
18
+ $ sql = "SELECT * FROM $ table " ;
19
+ $ sql .= $ limit ? " LIMIT $ limit " : "" ;
20
+
21
+ return $ this ->MySql ->queryAndFetch ($ sql );
17
22
}
18
23
19
- public function Where (string $ table , string $ field , $ value )
24
+ public function Where (string $ table , string $ field , $ value, int $ limit = null )
20
25
{
21
26
$ valueCorrection = gettype ($ value ) == "string " ? "' $ value' " : $ value ;
22
27
23
- return $ this ->MySql ->queryAndFetch ("SELECT * FROM $ table WHERE $ field = $ valueCorrection " );
28
+ $ sql = "SELECT * FROM $ table WHERE $ field = $ valueCorrection " ;
29
+ $ sql .= $ limit ? " LIMIT $ limit " : "" ;
30
+
31
+ return $ this ->MySql ->queryAndFetch ($ sql );
24
32
}
25
33
26
- public function Like (string $ table , string $ field , $ value )
34
+ public function Like (string $ table , string $ field , $ value, int $ limit = null )
27
35
{
28
36
$ valueType = gettype ($ value );
29
37
30
38
if ($ valueType == "string " ) {
31
- return $ this ->MySql ->queryAndFetch ("SELECT * FROM $ table WHERE $ field LIKE '% $ value%' " );
39
+ $ sql = "SELECT * FROM $ table WHERE $ field LIKE '% $ value%' " ;
40
+ $ sql .= $ limit ? " LIMIT $ limit " : "" ;
41
+
42
+ return $ this ->MySql ->queryAndFetch ($ sql );
32
43
} else {
33
44
$ message = "Value type is incorrect. Value has to be an String. Value type: " . $ valueType ;
34
45
35
46
throw new \RuntimeException ($ message );
36
47
}
37
48
}
38
- }
49
+ }
0 commit comments