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 PDO; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class DB |
25
|
|
|
* |
26
|
|
|
* Esta clase proporciona acceso directo a la base de datos. |
27
|
|
|
* |
28
|
|
|
* @author Rafael San José Tovar <[email protected]> |
29
|
|
|
* @version 2022.0721 |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
class DB |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Motor utilizado, puede ser MySql, MariaDB, PostgreSql o cualquier otro PDO |
36
|
|
|
* |
37
|
|
|
* @var Engine |
38
|
|
|
*/ |
39
|
|
|
public static $engine; |
40
|
|
|
|
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
if (!isset(self::$engine)) { |
44
|
|
|
$config = [ |
45
|
|
|
'dbName' => constant('FS_DB_NAME'), |
46
|
|
|
'dbUser' => constant('FS_DB_USER'), |
47
|
|
|
'dbPass' => constant('FS_DB_PASS'), |
48
|
|
|
'dbHost' => constant('FS_DB_HOST'), |
49
|
|
|
'dbPort' => constant('FS_DB_PORT'), |
50
|
|
|
'dbOptions' => [ |
51
|
|
|
// PDO::ATTR_EMULATE_PREPARES => false, |
52
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$engine = constant('FS_DB_TYPE'); |
57
|
|
|
switch (mb_strtolower($engine)) { |
58
|
|
|
case 'mysql': |
59
|
|
|
self::$engine = new MySql($config); |
|
|
|
|
60
|
|
|
break; |
61
|
|
|
case 'mariadb': |
62
|
|
|
self::$engine = new MariaDb($config); |
|
|
|
|
63
|
|
|
break; |
64
|
|
|
case 'postgresql': |
65
|
|
|
self::$engine = new PostgreSql($config); |
|
|
|
|
66
|
|
|
break; |
67
|
|
|
default: |
68
|
|
|
die('Unknown engine: ' . $engine); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static function connect() |
74
|
|
|
{ |
75
|
|
|
return self::$engine->connect(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function disconnect() |
79
|
|
|
{ |
80
|
|
|
return self::$engine->disconnect(); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public static function connected() |
84
|
|
|
{ |
85
|
|
|
return self::$engine->connected(); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Ejecuta una sentencia SQL retornando TRUE si ha tenido éxito |
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 bool |
98
|
|
|
*/ |
99
|
|
|
public static function exec(string $query, array $vars = []): bool |
100
|
|
|
{ |
101
|
|
|
return self::$engine->exec($query, $vars); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Ejecuta una sentencia SELECT, retornando false si hay error, o un array |
106
|
|
|
* con el resultado de la consulta. |
107
|
|
|
* |
108
|
|
|
* @author Rafael San José Tovar <[email protected]> |
109
|
|
|
* @version 2022.0721 |
110
|
|
|
* |
111
|
|
|
* @param string $query |
112
|
|
|
* @param array $vars |
113
|
|
|
* |
114
|
|
|
* @return array|false |
115
|
|
|
*/ |
116
|
|
|
public static function select(string $query, array $vars = []) |
117
|
|
|
{ |
118
|
|
|
return self::$engine->select($query, $vars); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public static function getErrors() |
122
|
|
|
{ |
123
|
|
|
return self::$engine->getErrors(); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public static function beginTransaction() |
127
|
|
|
{ |
128
|
|
|
return self::$engine->beginTransaction(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public static function commit() |
132
|
|
|
{ |
133
|
|
|
return self::$engine->commit(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public static function close() |
137
|
|
|
{ |
138
|
|
|
return self::$engine->close(); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public static function rollback() |
142
|
|
|
{ |
143
|
|
|
return self::$engine->rollback(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public static function version() |
147
|
|
|
{ |
148
|
|
|
return self::$engine->server_info(); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths