|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the MIT license. For more information, see |
|
18
|
|
|
* @category |
|
19
|
|
|
* @package sistema/nucleo |
|
20
|
|
|
* @copyright Copyright (c) 2006 - 2014 webcol.net (http://www.webcol.net/calima) |
|
21
|
|
|
* @license https://github.com/webcol/Calima/blob/master/LICENSE MIT |
|
22
|
|
|
* @version ##BETA 1.0##, ##2014 - 2015## |
|
23
|
|
|
* <http://www.calimaframework.com>. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace Sistema\Nucleo; |
|
27
|
|
|
|
|
28
|
|
|
class CFBasedatos |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
private $host = CF_BD_HOST; |
|
32
|
|
|
private $usuario = CF_BD_USUARIO; |
|
33
|
|
|
private $clave = CF_BD_CLAVE; |
|
34
|
|
|
private $bdnombre = CF_BD_NOMBRE; |
|
35
|
|
|
private $bdchar = CF_BD_CHAR; |
|
|
|
|
|
|
36
|
|
|
private $bdconector = CF_BD_CONECTOR; |
|
37
|
|
|
private $stmt; |
|
38
|
|
|
private $dbh; |
|
39
|
|
|
private $error; |
|
40
|
|
|
protected $db; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct() { |
|
43
|
|
|
// definimos el dsn |
|
44
|
|
|
$dns = $this->bdconector . ':host=' . $this->host . ';dbname=' . $this->bdnombre; |
|
45
|
|
|
|
|
46
|
|
|
// Opciones para PDO |
|
47
|
|
|
|
|
48
|
|
|
$options = array( |
|
49
|
|
|
\PDO::ATTR_PERSISTENT => true, |
|
50
|
|
|
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, |
|
51
|
|
|
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" |
|
52
|
|
|
); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
// creamos una instancia de PDO |
|
56
|
|
|
try { |
|
57
|
|
|
$this->dbh = new \PDO($dns, $this->usuario, $this->clave, $options); |
|
58
|
|
|
} |
|
59
|
|
|
// Catch algunos errores |
|
60
|
|
|
catch (PDOException $e) { |
|
|
|
|
|
|
61
|
|
|
$this->error = $e->getMessage(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function consulta($query) { |
|
66
|
|
|
$this->stmt = $this->dbh->prepare($query); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function enlace($param, $value, $type = null) {//bind |
|
70
|
|
|
if (is_null($type)) { |
|
71
|
|
|
switch (true) { |
|
72
|
|
|
case is_int($value): |
|
73
|
|
|
$type = \PDO::PARAM_INT; |
|
74
|
|
|
break; |
|
75
|
|
|
case is_bool($value): |
|
76
|
|
|
$type = \PDO::PARAM_BOOL; |
|
77
|
|
|
break; |
|
78
|
|
|
case is_null($value): |
|
79
|
|
|
$type = \PDO::PARAM_NULL; |
|
80
|
|
|
break; |
|
81
|
|
|
default: |
|
82
|
|
|
$type = \PDO::PARAM_STR; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
$this->stmt->bindValue($param, $value, $type); //bindValue de PDO php |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function ejecucion() { |
|
89
|
|
|
return $this->stmt->execute(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function resultset() { |
|
93
|
|
|
$this->ejecucion(); |
|
94
|
|
|
return $this->stmt->fetchAll(\PDO::FETCH_ASSOC); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function primeraColumna() { |
|
98
|
|
|
$this->ejecucion(); |
|
99
|
|
|
return $this->stmt->fetchColumn(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function PrimerRegistro() { |
|
103
|
|
|
$this->ejecucion(); |
|
104
|
|
|
return $this->stmt->fetch(\PDO::FETCH_ASSOC); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function contarFilas() { |
|
108
|
|
|
return $this->stmt->rowCount(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function lastInsertId() { |
|
112
|
|
|
return $this->dbh->lastInsertId(); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function beginTransaction() { |
|
116
|
|
|
return $this->dbh->beginTransaction(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function endTransaction() { |
|
120
|
|
|
return $this->dbh->commit(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function cancelTransaction() { |
|
124
|
|
|
return $this->dbh->rollBack(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function debugDumpParams() { |
|
128
|
|
|
return $this->stmt->debugDumpParams(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function single() { |
|
132
|
|
|
$this->ejecucion(); |
|
133
|
|
|
return $this->stmt->fetch(\PDO::FETCH_ASSOC); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.