-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_handler.php
executable file
·47 lines (47 loc) · 1.76 KB
/
sql_handler.php
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
<?php
class SQLHandler {
public $conn;
function __construct(){
$this->conn=new mysqli("NIE POWIEM", "TEŻ NIE POWIEM", "TYM BARDZIEJ NIE POWIEM", "DOSYĆ");
}
function __destruct(){
$this->conn->close();
}
function queryRowsGenerator($stmtBody, $param_types, $params){
//echo "k";
$stmt=$this->conn->prepare($stmtBody);
//call_user_func_array([$stmt, 'bind_param'], array_merge([$param_types], $params)); TROUBLE
//var_dump([ 'param_types'=>$param_types, 'params'=>$params ]);
//throw new Exception('AAAAA');
if(count($params)>0){
$stmt->bind_param($param_types, ...$params);
}
$stmt->execute();
$res=$stmt->get_result();
while($row=$res->fetch_assoc()){
yield $row;
}
}
function queryRowsArray($stmtBody, $param_types, $params){
$stmt=$this->conn->prepare($stmtBody);
$stmt->bind_param($param_types, ...$params);
$stmt->execute();
$res=$stmt->get_result();
$rows=[];
while($row=$res->fetch_assoc()){
$rows[]=$row;
}
return $rows;
}
function queryRow($stmtBody, $param_types, $params){
$rows=$this->queryRowsGenerator($stmtBody, $param_types, $params);
if(!$rows->valid()) return false;
return $rows->current();
}
function execute($stmtBody, $param_types, $params){
$stmt=$this->conn->prepare($stmtBody);
$stmt->bind_param($param_types, ...$params);
$stmt->execute();
}
}
?>