TRF Certest first commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require_once 'class/db-functions.php';
|
||||
|
||||
$response = ["success" => false, "columns" => []];
|
||||
|
||||
try {
|
||||
if (!isset($_GET['table']) || empty($_GET['table'])) {
|
||||
throw new Exception("Invalid table name.");
|
||||
}
|
||||
|
||||
$table = preg_replace('/[^a-zA-Z0-9_]/', '', $_GET['table']); // Sanitize table name
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Retrieve table columns
|
||||
$stmt = $pdo->query("SHOW COLUMNS FROM `$table`");
|
||||
$columns = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
if (!$columns) {
|
||||
throw new Exception("No columns found in table.");
|
||||
}
|
||||
|
||||
$response["success"] = true;
|
||||
$response["columns"] = $columns;
|
||||
} catch (Exception $e) {
|
||||
$response["message"] = $e->getMessage();
|
||||
}
|
||||
|
||||
// Log per debugging
|
||||
error_log(json_encode($response));
|
||||
|
||||
// Restituisce la risposta JSON
|
||||
echo json_encode($response);
|
||||
Reference in New Issue
Block a user