Merge pull request #5269 from annando/non-unique-values
This fixes the problem with mixed variables in queries
This commit is contained in:
commit
47ab72352e
1 changed files with 37 additions and 1 deletions
|
@ -76,6 +76,9 @@ class dba {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
self::$db = @new PDO($connect, $user, $pass);
|
self::$db = @new PDO($connect, $user, $pass);
|
||||||
|
// Needs more testing
|
||||||
|
//self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
|
||||||
|
//self::$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
|
||||||
self::$connected = true;
|
self::$connected = true;
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
}
|
}
|
||||||
|
@ -1296,6 +1299,39 @@ class dba {
|
||||||
$condition_string .= " AND ";
|
$condition_string .= " AND ";
|
||||||
}
|
}
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
|
// Check if there are integer values in the parameters
|
||||||
|
$is_int = false;
|
||||||
|
$is_float = false;
|
||||||
|
$is_alpha = false;
|
||||||
|
foreach ($value as $single_value) {
|
||||||
|
if (is_int($single_value)) {
|
||||||
|
$is_int = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// To prevent to round floats we look for them
|
||||||
|
if (round($single_value) != (float)$single_value) {
|
||||||
|
$is_float = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is any non numeric value present?
|
||||||
|
if (!is_numeric($single_value)) {
|
||||||
|
$is_alpha = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cast them all in an unique method
|
||||||
|
if ($is_int) {
|
||||||
|
$casted = [];
|
||||||
|
foreach ($value as $single_value) {
|
||||||
|
if (!$is_alpha && !$is_float) {
|
||||||
|
$casted[] = (int)$single_value;
|
||||||
|
} else {
|
||||||
|
$casted[] = (string)$single_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$value = $casted;
|
||||||
|
}
|
||||||
|
|
||||||
$new_values = array_merge($new_values, array_values($value));
|
$new_values = array_merge($new_values, array_values($value));
|
||||||
$placeholders = substr(str_repeat("?, ", count($value)), 0, -2);
|
$placeholders = substr(str_repeat("?, ", count($value)), 0, -2);
|
||||||
$condition_string .= "`" . $field . "` IN (" . $placeholders . ")";
|
$condition_string .= "`" . $field . "` IN (" . $placeholders . ")";
|
||||||
|
|
Loading…
Reference in a new issue