Fix: 500 error(DB logic) and Geolocation timeout issue

This commit is contained in:
2025-12-14 15:42:40 +09:00
parent 0716754bf5
commit fb5a954691
15 changed files with 228 additions and 35 deletions

12
output/debug_schema.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
$_SERVER['DOCUMENT_ROOT'] = 'c:/Users/light/sam/5130';
require_once 'c:/Users/light/sam/5130/lib/mydb.php';
try {
$pdo = db_connect();
$stmt = $pdo->query("SHOW COLUMNS FROM output LIKE 'num'");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>

View File

@@ -0,0 +1,54 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$_SERVER['DOCUMENT_ROOT'] = 'c:/Users/light/sam/5130';
require_once 'c:/Users/light/sam/5130/lib/mydb.php';
echo "Starting DB Schema Fix...\n";
try {
// Connect directly to avoid .env overwriting with 'mysql' host
$dsn = "mysql:host=127.0.0.1;dbname=chandj;charset=utf8";
$pdo = new PDO($dsn, 'root', 'root');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$DB = 'chandj';
// 1. Fix output table
echo "Fixing 'output' table...\n";
// Check if auto_increment exists or just try to apply it
// Usually 'MODIFY num INT AUTO_INCREMENT' works. Assuming 'num' is int.
// We also need to make sure we don't break existing keys.
// Safest is "MODIFY num INT NOT NULL AUTO_INCREMENT"
$sql = "ALTER TABLE {$DB}.output MODIFY num INT NOT NULL AUTO_INCREMENT";
$pdo->exec($sql);
echo " - 'output.num' set to AUTO_INCREMENT successfully.\n";
} catch (Exception $e) {
echo " - Error fixing 'output': " . $e->getMessage() . "\n";
}
try {
// 2. Fix geo_attendance table
// First, find the primary key column name
echo "Fixing 'geo_attendance' table...\n";
$stmt = $pdo->query("SHOW KEYS FROM {$DB}.geo_attendance WHERE Key_name = 'PRIMARY'");
$pk = $stmt->fetch(PDO::FETCH_ASSOC);
if ($pk) {
$pkColumn = $pk['Column_name'];
echo " - Found Primary Key column: $pkColumn\n";
$sql = "ALTER TABLE {$DB}.geo_attendance MODIFY $pkColumn INT NOT NULL AUTO_INCREMENT";
$pdo->exec($sql);
echo " - 'geo_attendance.$pkColumn' set to AUTO_INCREMENT successfully.\n";
} else {
echo " - Could not find Primary Key for geo_attendance.\n";
}
} catch (Exception $e) {
echo " - Error fixing 'geo_attendance': " . $e->getMessage() . "\n";
}
echo "Done.\n";
?>

View File

@@ -1,12 +1,12 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
header("Content-Type: application/json");
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : '';
@@ -157,9 +157,12 @@ $searchtag = rtrim($searchtag, ' ');
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
$DB = $_ENV['DB_NAME'] ?? 'chandj';
try {
if ($mode == "insert" || $mode == "copy") {
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " ";
$pdo->beginTransaction();
@@ -178,6 +181,7 @@ try {
?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmh = $pdo->prepare($sql);
$stmh->execute([
$outdate, $indate, $orderman, $outworkplace, $outputplace,
$receiver, $phone, $comment, $con_num, $root,
@@ -291,7 +295,8 @@ try {
$pdo->commit();
} catch (Exception $ex) {
$pdo->rollBack();
print "오류: ".$Exception->getMessage();
// print "오류: ".$Exception->getMessage();
throw new Exception($ex->getMessage());
}
}
@@ -317,7 +322,8 @@ try {
$pdo->commit();
} catch (PDOException $Exception) {
$pdo->rollBack();
print "오류: ".$Exception->getMessage();
// print "오류: ".$Exception->getMessage();
throw new Exception($Exception->getMessage());
}
}

View File

@@ -1 +1 @@
250717-02
251214-03