38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
echo "Starting Geo Attendance DB Fix...\n";
|
|
|
|
try {
|
|
// Connect directly
|
|
$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);
|
|
|
|
// 1. Check for ID 0 and move it if exists
|
|
// We use a subquery to find a safe new ID
|
|
echo "Checking for ID 0...\n";
|
|
$stmt = $pdo->query("SELECT count(*) FROM geo_attendance WHERE id = 0");
|
|
if ($stmt->fetchColumn() > 0) {
|
|
echo " - Found row with ID 0. Moving it to a new ID...\n";
|
|
// Calculate max id + 1
|
|
$stmt = $pdo->query("SELECT MAX(id) FROM geo_attendance");
|
|
$maxId = $stmt->fetchColumn();
|
|
$newId = ($maxId > 0 ? $maxId : 0) + 1;
|
|
|
|
$pdo->exec("UPDATE geo_attendance SET id = $newId WHERE id = 0");
|
|
echo " - ID 0 moved to $newId.\n";
|
|
}
|
|
|
|
// 2. Apply AUTO_INCREMENT
|
|
echo "Applying AUTO_INCREMENT to 'id' column...\n";
|
|
$sql = "ALTER TABLE geo_attendance MODIFY id INT NOT NULL AUTO_INCREMENT";
|
|
$pdo->exec($sql);
|
|
echo " - Success! 'geo_attendance.id' is now AUTO_INCREMENT.\n";
|
|
|
|
} catch (Exception $e) {
|
|
echo "Error: " . $e->getMessage() . "\n";
|
|
}
|
|
?>
|