3
3
namespace UnityWebPortal \lib ;
4
4
5
5
use PDO ;
6
+ use PDOException ;
6
7
7
8
class UnitySQL
8
9
{
@@ -35,16 +36,28 @@ public function getConn()
35
36
return $ this ->conn ;
36
37
}
37
38
39
+ private function execute ($ statement )
40
+ {
41
+ try {
42
+ $ statement ->execute ();
43
+ } catch (PDOException $ e ) {
44
+ ob_start ();
45
+ $ statement ->debugDumpParams ();
46
+ $ sql_debug_dump = ob_get_clean ();
47
+ throw new PDOException ($ sql_debug_dump , 0 , $ e );
48
+ }
49
+ }
50
+
38
51
private function search ($ table , $ filters )
39
52
{
40
53
$ stmt = $ this ->conn ->prepare (
41
54
"SELECT * FROM $ table WHERE " .
42
55
implode (" and " , array_map (fn ($ x ) => "$ x=: $ x " , array_keys ($ filters )))
43
56
);
44
57
foreach ($ filters as $ key => $ val ) {
45
- $ stmt ->bindParam (": $ key " , $ val );
58
+ $ stmt ->bindValue (": $ key " , $ val );
46
59
}
47
- $ stmt ->execute ();
60
+ $ this ->execute ($ stmt );
48
61
return $ stmt ->fetchAll ();
49
62
}
50
63
@@ -55,9 +68,9 @@ private function delete($table, $filters)
55
68
implode (" and " , array_map (fn ($ x ) => "$ x=: $ x " , array_keys ($ filters )))
56
69
);
57
70
foreach ($ filters as $ key => $ val ) {
58
- $ stmt ->bindParam (": $ key " , $ val );
71
+ $ stmt ->bindValue (": $ key " , $ val );
59
72
}
60
- $ stmt ->execute ();
73
+ $ this ->execute ($ stmt );
61
74
}
62
75
63
76
private function insert ($ table , $ data )
@@ -69,9 +82,9 @@ private function insert($table, $data)
69
82
"( " . implode (", " , array_map (fn ($ x ) => ": $ x " , array_keys ($ data ))) . ") "
70
83
);
71
84
foreach ($ data as $ key => $ val ) {
72
- $ stmt ->bindParam (": $ key " , $ val );
85
+ $ stmt ->bindValue (": $ key " , $ val );
73
86
}
74
- $ stmt ->execute ();
87
+ $ this ->execute ($ stmt );
75
88
}
76
89
77
90
private function update ($ table , $ filters , $ data )
@@ -84,11 +97,12 @@ private function update($table, $filters, $data)
84
97
implode (" and " , array_map (fn ($ x ) => "$ x=: $ x " , array_keys ($ filters )))
85
98
);
86
99
foreach ($ filters as $ key => $ val ) {
87
- $ stmt ->bindParam (": $ key " , $ val );
100
+ $ stmt ->bindValue (": $ key " , $ val );
88
101
}
89
102
foreach ($ data as $ key => $ val ) {
90
- $ stmt ->bindParam (": $ key " , $ val );
103
+ $ stmt ->bindValue (": $ key " , $ val );
91
104
}
105
+ $ this ->execute ($ stmt );
92
106
$ stmt ->execute ();
93
107
}
94
108
@@ -108,7 +122,7 @@ public function removeRequest($requestor, $dest = self::REQUEST_BECOME_PI)
108
122
if (!$ this ->requestExists ($ requestor , $ dest )) {
109
123
return ;
110
124
}
111
- $ this ->delete (self ::TABLE_REQS , ["uid " => $ uid , "request_for " => $ dest ]);
125
+ $ this ->delete (self ::TABLE_REQS , ["uid " => $ requestor , "request_for " => $ dest ]);
112
126
}
113
127
114
128
public function removeRequests ($ dest = self ::REQUEST_BECOME_PI )
@@ -250,8 +264,8 @@ public function getRole($uid, $group)
250
264
$ stmt = $ this ->conn ->prepare (
251
265
"SELECT * FROM " . self ::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group "
252
266
);
253
- $ stmt ->bindParam (":uid " , $ uid );
254
- $ stmt ->bindParam (":group " , $ group );
267
+ $ stmt ->bindValue (":uid " , $ uid );
268
+ $ stmt ->bindValue (":group " , $ group );
255
269
256
270
$ stmt ->execute ();
257
271
@@ -263,7 +277,7 @@ public function hasPerm($role, $perm)
263
277
$ stmt = $ this ->conn ->prepare (
264
278
"SELECT * FROM " . self ::TABLE_GROUP_ROLES . " WHERE slug=:role "
265
279
);
266
- $ stmt ->bindParam (":role " , $ role );
280
+ $ stmt ->bindValue (":role " , $ role );
267
281
268
282
$ stmt ->execute ();
269
283
@@ -277,7 +291,7 @@ public function getPriority($role)
277
291
$ stmt = $ this ->conn ->prepare (
278
292
"SELECT * FROM " . self ::TABLE_GROUP_ROLES . " WHERE slug=:role "
279
293
);
280
- $ stmt ->bindParam (":role " , $ role );
294
+ $ stmt ->bindValue (":role " , $ role );
281
295
282
296
$ stmt ->execute ();
283
297
@@ -290,8 +304,8 @@ public function roleAvailableInGroup($uid, $group, $role)
290
304
$ stmt = $ this ->conn ->prepare (
291
305
"SELECT * FROM " . self ::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group "
292
306
);
293
- $ stmt ->bindParam (":uid " , $ uid );
294
- $ stmt ->bindParam (":group " , $ group );
307
+ $ stmt ->bindValue (":uid " , $ uid );
308
+ $ stmt ->bindValue (":group " , $ group );
295
309
296
310
$ stmt ->execute ();
297
311
$ row = $ stmt ->fetchAll ()[0 ];
@@ -302,7 +316,7 @@ public function roleAvailableInGroup($uid, $group, $role)
302
316
"SELECT * FROM " . self ::TABLE_GROUP_TYPES . " WHERE slug=:slug "
303
317
);
304
318
305
- $ stmt ->bindParam (":slug " , $ group_slug );
319
+ $ stmt ->bindValue (":slug " , $ group_slug );
306
320
$ stmt ->execute ();
307
321
308
322
$ row = $ stmt ->fetchAll ()[0 ];
0 commit comments