|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2022-2023 Rafael San José Tovar <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Alxarafe\Database; |
|
20
|
|
|
|
|
21
|
|
|
use Alxarafe\Core\Singletons\Config; |
|
22
|
|
|
use Alxarafe\Database\SqlHelpers\SqlMySql; |
|
23
|
|
|
use PDO; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class DB |
|
27
|
|
|
* |
|
28
|
|
|
* Esta clase proporciona acceso directo a la base de datos. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Rafael San José Tovar <[email protected]> |
|
31
|
|
|
* @version 2022.0721 |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
|
|
class DB |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Motor utilizado, puede ser MySql, MariaDB, PostgreSql o cualquier otro PDO |
|
38
|
|
|
* |
|
39
|
|
|
* @var Engine |
|
40
|
|
|
*/ |
|
41
|
|
|
public static $engine; |
|
42
|
|
|
|
|
43
|
|
|
public static $sqlHelper; |
|
44
|
|
|
|
|
45
|
|
|
public function __construct() |
|
46
|
|
|
{ |
|
47
|
|
|
self::$engine = Config::getEngine(); |
|
48
|
|
|
self::$sqlHelper = Config::getSqlHelper(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function connect() |
|
52
|
|
|
{ |
|
53
|
|
|
return self::$engine->connect(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function disconnect() |
|
57
|
|
|
{ |
|
58
|
|
|
return self::$engine->disconnect(); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public static function connected() |
|
62
|
|
|
{ |
|
63
|
|
|
return self::$engine->connected(); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public static function getDataTypes() |
|
67
|
|
|
{ |
|
68
|
|
|
return self::$sqlHelper->getDataTypes(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Ejecuta una sentencia SQL retornando TRUE si ha tenido éxito |
|
73
|
|
|
* |
|
74
|
|
|
* @author Rafael San José Tovar <[email protected]> |
|
75
|
|
|
* @version 2022.0721 |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $query |
|
78
|
|
|
* @param array $vars |
|
79
|
|
|
* |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public static function exec(string $query, array $vars = []): bool |
|
83
|
|
|
{ |
|
84
|
|
|
return self::$engine->exec($query, $vars); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Ejecuta una sentencia SELECT, retornando false si hay error, o un array |
|
89
|
|
|
* con el resultado de la consulta. |
|
90
|
|
|
* |
|
91
|
|
|
* @author Rafael San José Tovar <[email protected]> |
|
92
|
|
|
* @version 2022.0721 |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $query |
|
95
|
|
|
* @param array $vars |
|
96
|
|
|
* |
|
97
|
|
|
* @return array|false |
|
98
|
|
|
*/ |
|
99
|
|
|
public static function select(string $query, array $vars = []) |
|
100
|
|
|
{ |
|
101
|
|
|
return self::$engine->select($query, $vars); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public static function getErrors() |
|
105
|
|
|
{ |
|
106
|
|
|
return self::$engine->getErrors(); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public static function beginTransaction() |
|
110
|
|
|
{ |
|
111
|
|
|
return self::$engine->beginTransaction(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public static function commit() |
|
115
|
|
|
{ |
|
116
|
|
|
return self::$engine->commit(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public static function close() |
|
120
|
|
|
{ |
|
121
|
|
|
return self::$engine->close(); |
|
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public static function rollback() |
|
125
|
|
|
{ |
|
126
|
|
|
return self::$engine->rollback(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public static function version() |
|
130
|
|
|
{ |
|
131
|
|
|
return self::$engine->server_info(); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.