refactor(model): Use match expression for PDO type detection
This commit is contained in:
@@ -157,17 +157,13 @@ class Model
|
|||||||
try {
|
try {
|
||||||
$prepared = $db->prepare($query);
|
$prepared = $db->prepare($query);
|
||||||
foreach (static::$dbQueryVariables as $key => $value) {
|
foreach (static::$dbQueryVariables as $key => $value) {
|
||||||
// Detectar el tipo de dato para elegir la constante de PDO
|
// Detect data type to choose the PDO constant
|
||||||
$type = PDO::PARAM_STR; // Por defecto string
|
$type = match (gettype($value)) {
|
||||||
if (is_int($value)) {
|
'integer' => PDO::PARAM_INT,
|
||||||
$type = PDO::PARAM_INT;
|
'boolean' => PDO::PARAM_BOOL,
|
||||||
}
|
'NULL' => PDO::PARAM_NULL,
|
||||||
if (is_bool($value)) {
|
default => PDO::PARAM_STR,
|
||||||
$type = PDO::PARAM_BOOL;
|
};
|
||||||
}
|
|
||||||
if (is_null($value)) {
|
|
||||||
$type = PDO::PARAM_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
$prepared->bindValue($key, $value, $type);
|
$prepared->bindValue($key, $value, $type);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user