|
1
|
|
|
<?php |
|
2
|
|
|
class Query extends Module { |
|
|
|
|
|
|
3
|
|
|
public $connection; |
|
4
|
|
|
public $currentConnection; |
|
5
|
|
|
public function __construct() { |
|
6
|
|
|
parent::__construct(); |
|
7
|
|
|
$this->connection = []; |
|
8
|
|
|
$this->currentConnection = null; |
|
9
|
|
|
} |
|
10
|
|
|
public function addConnection( $_name, $_connection ) { |
|
11
|
|
|
$this->connection["$_name"] = $_connection; |
|
12
|
|
|
$this->currentConnection = $_connection; |
|
13
|
|
|
} |
|
14
|
|
|
public function setConnection( $_name ) { |
|
15
|
|
|
$this->currentConnection = $this->connection["$_name"]; |
|
16
|
|
|
} |
|
17
|
|
|
public function query( $_query ) { |
|
18
|
|
|
$this->stdQuery($_query); |
|
19
|
|
|
return true; |
|
20
|
|
|
} |
|
21
|
|
|
public function queryInsert( $_query ) { |
|
22
|
|
|
$temp = $this->stdQuery($_query); |
|
|
|
|
|
|
23
|
|
|
return $this->currentConnection->database->lastInsertId(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function queryFetch( $_query ) { |
|
27
|
|
|
$temp = $this->stdQuery($_query); |
|
28
|
|
|
return $temp->fetchAll(PDO::FETCH_ASSOC); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function queryArray( $_query ) { |
|
32
|
|
|
$temp = $this->stdQuery($_query); |
|
33
|
|
|
return $temp->fetchAll(PDO::FETCH_COLUMN, 0); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function stdQuery($_query) { |
|
37
|
|
|
$database = $this->currentConnection->database; |
|
38
|
|
|
$error = "Errore query [$_query]"; |
|
39
|
|
|
$query = $database->prepare($_query); |
|
40
|
|
|
$_result = $query->execute(); |
|
41
|
|
|
if(!$_result) { |
|
42
|
|
|
echo "$_query<br>"; |
|
43
|
|
|
echo "Something wrong: ".$error; |
|
44
|
|
|
var_dump($query->errorInfo()); |
|
|
|
|
|
|
45
|
|
|
var_dump($database->errorInfo()); |
|
46
|
|
|
exit(); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
return $query; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
?> |
|
|
|
|
|
|
52
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.