add dropdown menu for FK values
This commit is contained in:
@@ -197,10 +197,7 @@ private function formatPDOError(\PDOException $e, string $schema, string $table,
|
||||
public function updateRow(string $schema, string $table, array $row, array $columns, array $pk): array
|
||||
{
|
||||
error_log("=== UPDATE ROW ===");
|
||||
error_log("Schema: $schema");
|
||||
error_log("Table: $table");
|
||||
error_log("Row data: " . json_encode($row, JSON_UNESCAPED_UNICODE));
|
||||
error_log("PK: " . json_encode($pk));
|
||||
error_log("Schema: $schema, Table: $table");
|
||||
|
||||
if (empty($pk)) {
|
||||
throw new \RuntimeException('No primary key — update disabled');
|
||||
@@ -221,14 +218,12 @@ public function updateRow(string $schema, string $table, array $row, array $colu
|
||||
}
|
||||
|
||||
if (empty($sets)) {
|
||||
error_log("No changes to update");
|
||||
return ['updated' => 0, 'message' => 'No changes'];
|
||||
}
|
||||
|
||||
$whereParts = [];
|
||||
foreach ($pk as $name) {
|
||||
if (!array_key_exists($name, $row)) {
|
||||
error_log("ERROR: Missing PK value: $name");
|
||||
throw new \RuntimeException("Missing PK value: $name");
|
||||
}
|
||||
$whereParts[] = "`$name` = :pk_$name";
|
||||
@@ -242,20 +237,24 @@ public function updateRow(string $schema, string $table, array $row, array $colu
|
||||
implode(' AND ', $whereParts)
|
||||
);
|
||||
|
||||
error_log("SQL: $sql");
|
||||
error_log("Params: " . json_encode($params, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
$rowCount = $stmt->rowCount();
|
||||
error_log("Rows updated: $rowCount");
|
||||
error_log("=== UPDATE COMPLETE ===");
|
||||
|
||||
return ['updated' => $rowCount];
|
||||
// ✅ Обрабатываем ошибки с красивым сообщением
|
||||
try {
|
||||
$stmt->execute($params);
|
||||
$rowCount = $stmt->rowCount();
|
||||
error_log("Rows updated: $rowCount");
|
||||
return ['updated' => $rowCount];
|
||||
} catch (\PDOException $e) {
|
||||
error_log("UPDATE FAILED: " . $e->getMessage());
|
||||
|
||||
// Форматируем ошибку для пользователя
|
||||
throw new \RuntimeException($this->formatPDOError($e, $schema, $table, $params));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function deleteRow(string $schema, string $table, array $row, array $pk): array
|
||||
{
|
||||
if (empty($pk)) {
|
||||
|
||||
Reference in New Issue
Block a user