1
|
|
|
<?php |
2
|
|
|
############################################################################### |
3
|
|
|
# ASTPP - Open Source VoIP Billing Solution |
4
|
|
|
# |
5
|
|
|
# Copyright (C) 2016 iNextrix Technologies Pvt. Ltd. |
6
|
|
|
# Samir Doshi <[email protected]> |
7
|
|
|
# ASTPP Version 3.0 and above |
8
|
|
|
# License https://www.gnu.org/licenses/agpl-3.0.html |
9
|
|
|
# |
10
|
|
|
# This program is free software: you can redistribute it and/or modify |
11
|
|
|
# it under the terms of the GNU Affero General Public License as |
12
|
|
|
# published by the Free Software Foundation, either version 3 of the |
13
|
|
|
# License, or (at your option) any later version. |
14
|
|
|
# |
15
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
# GNU Affero General Public License for more details. |
19
|
|
|
# |
20
|
|
|
# You should have received a copy of the GNU Affero General Public License |
21
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
############################################################################### |
23
|
|
|
|
24
|
|
|
class db extends PDO { |
25
|
|
|
|
26
|
|
|
private $error; |
27
|
|
|
private $sql; |
28
|
|
|
private $bind; |
29
|
|
|
private $errorCallbackFunction; |
|
|
|
|
30
|
|
|
private $errorMsgFormat; |
|
|
|
|
31
|
|
|
|
32
|
|
|
public function __construct($dsn = "", $user = "", $passwd = "") { |
33
|
|
|
|
34
|
|
|
$config = parse_ini_file("/var/lib/astpp/astpp-config.conf"); |
35
|
|
|
|
36
|
|
|
$options = array( |
37
|
|
|
PDO::ATTR_PERSISTENT => true, |
38
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
try { |
42
|
|
|
parent::__construct("mysql:host=".$config['dbhost'].";dbname=".$config['dbname']."", $config['dbuser'], $config['dbpass'], $options); |
43
|
|
|
} catch (PDOException $e) { |
44
|
|
|
|
45
|
|
|
$this->error = $e->getMessage(); |
46
|
|
|
} |
47
|
|
|
echo $this->error; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $bind |
52
|
|
|
*/ |
53
|
|
|
public function cleanup($bind) { |
54
|
|
|
if ( ! is_array($bind)) { |
55
|
|
|
if ( ! empty($bind)) |
56
|
|
|
$bind = array($bind); |
57
|
|
|
else |
58
|
|
|
$bind = array(); |
59
|
|
|
} |
60
|
|
|
return $bind; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function run($sql, $bind = "") { |
64
|
|
|
$this->sql = trim($sql); |
65
|
|
|
$this->bind = $this->cleanup($bind); |
66
|
|
|
$this->error = ""; |
67
|
|
|
|
68
|
|
|
try { |
69
|
|
|
$pdostmt = $this->prepare($this->sql); |
70
|
|
|
if ($pdostmt->execute($this->bind) !== false) { |
71
|
|
|
if (preg_match("/^(".implode("|", array("select", "describe", "pragma")).") /i", $this->sql)) |
72
|
|
|
return $pdostmt->fetchAll(PDO::FETCH_ASSOC); |
73
|
|
|
elseif (preg_match("/^(".implode("|", array("delete", "insert", "update")).") /i", $this->sql)) |
74
|
|
|
return $pdostmt->rowCount(); |
75
|
|
|
} |
76
|
|
|
} catch (PDOException $e) { |
77
|
|
|
$this->error = $e->getMessage(); |
78
|
|
|
return $this->error; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
?> |
|
|
|
|
85
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.