This commit is contained in:
2026-01-02 01:03:10 +01:00
parent a856086ce1
commit 1b077e10e2

View File

@@ -83,28 +83,28 @@ final class Search
$sql .= " LIMIT :lim"; $sql .= " LIMIT :lim";
$bind[':lim'] = (int)$limit; $bind[':lim'] = (int)$limit;
echo '<pre>';
print_r($bind);
echo '</pre>';
echo $sql;
$stmt = $this->pdo->prepare($sql); $stmt = $this->pdo->prepare($sql);
foreach ($bind as $name => $value) { foreach ($bind as $name => $value) {
$paramName = $name; $paramName = $name[0] === ':' ? $name : ':' . $name;
if ($name[0] !== ':') { $type = is_int($value) ? \PDO::PARAM_INT : \PDO::PARAM_STR;
$paramName = ':' . $name; $stmt->bindValue($paramName, $value, $type);
}
if (defined('APP_ENV') && APP_ENV === 'staging') {
$ph = [];
if (preg_match_all('/:([a-zA-Z0-9_]+)/', $sql, $m)) {
$ph = array_unique($m[0]);
} }
$stmt->bindValue($paramName, $value, \PDO::PARAM_STR); $paramKeys = array_keys($bind);
error_log('Search placeholders: ' . json_encode($ph));
error_log('Search params: ' . json_encode($paramKeys));
} }
// Limit als INT binden try {
$stmt->bindValue(':lim', (int)$bind[':lim'] ?? (int)$bind['lim'] ?? (int)$limit, \PDO::PARAM_INT); $stmt->execute();
// Radius nur falls existiert } catch (\PDOException $e) {
if ($distanceFiltering) { error_log('Search SQL: ' . $sql);
$stmt->bindValue(':radius', $bind[':radius'] ?? $bind['radius'], \PDO::PARAM_STR); error_log('Search bind: ' . print_r($bind, true));
throw $e;
} }
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: []; return $stmt->fetchAll(\PDO::FETCH_ASSOC) ?: [];
} }
} }