-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDOConfig.class.php
More file actions
65 lines (58 loc) · 1.65 KB
/
PDOConfig.class.php
File metadata and controls
65 lines (58 loc) · 1.65 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
class PDOConfig extends PDO
{
private $engine;
private $host;
private $database;
private $user;
private $pass;
private $debug;
public function __construct() {
$this->engine = 'mysql';
$this->host = 'localhost';
$this->database = 'db';
$this->user = 'root';
$this->pass = '';
$this->debug = false;
$dns = $this->engine . ':dbname=' . $this->database . ";host=" . $this->host;
return parent::__construct($dns, $this->user, $this->pass);
}
public function query($sql) {
if ($this->debug) {
echo "Consulta a ejecutar: /** " . $sql . ' **/ <br />';
}
$resultado = parent::query($sql);
if (!$resultado) {
if ($this->debug) {
print_r($this->errorInfo());
}
return false;
}else
return $resultado;
}
public function queryToArray($sql) {
if ($this->debug) {
echo "Consulta a ejecutar: /** " . $sql . ' **/ <br />';
}
$sth = parent::prepare($sql);
$sth->execute();
$resultado = $sth->fetchAll(PDO::FETCH_ASSOC);
if (!$resultado) {
if ($this->debug) {
print_r($this->errorInfo());
}
return false;
} else {
return $resultado;
}
}
public function setDebug($debug) {
$this->debug = $debug;
}
public function getDebug() {
return $this->debug;
}
public function limpiarVars($var) {
return addslashes(htmlentities($var));
}
}