From 10eedb49b2ebe98824c7d99884feb2015ec05dad Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 28 Feb 2026 06:01:25 +0000 Subject: [PATCH] install file 2 --- install.php | 94 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/install.php b/install.php index 976f985..45b21d3 100644 --- a/install.php +++ b/install.php @@ -35,8 +35,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Test connection try { - $pdo = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $pass); - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $test_pdo = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $pass); + $test_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Generate config file content $content = "setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n"; - $content .= " $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\n"; - $content .= " } catch (PDOException $e) {\n"; - $content .= " die('Connection failed: ' . $e->getMessage());\n"; + $content .= " \$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS);\n"; + $content .= " \$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n"; + $content .= " \$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\n"; + $content .= " } catch (PDOException \$e) {\n"; + $content .= " die('Connection failed: ' . \$e->getMessage());\n"; $content .= " }\n"; $content .= " }\n"; - $content .= " return $pdo;\n"; + $content .= " return \$pdo;\n"; $content .= " }\n"; $content .= "}\n"; @@ -84,6 +84,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pdo = db(); $migrations_dir = __DIR__ . '/db/migrations/'; $files = glob($migrations_dir . '*.sql'); + if ($files === false) $files = []; sort($files); $applied = 0; @@ -94,20 +95,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (empty($sql)) continue; try { - // PDO::exec might fail if there's an error in the SQL, - // but we want to continue if it's "column already exists" or "table already exists" - $pdo->exec($sql); + // Split SQL into multiple statements if necessary + // Simple split by semicolon. This might fail on some complex SQL, + // but usually works for basic migrations. + $statements = array_filter(array_map('trim', explode(';', $sql))); + foreach ($statements as $stmt_sql) { + if (empty($stmt_sql)) continue; + try { + $pdo->exec($stmt_sql); + } catch (Throwable $e) { + $msg = $e->getMessage(); + // Check if it's a common "already exists" error which we can safely ignore + if (strpos($msg, 'Duplicate column name') !== false || + strpos($msg, 'Duplicate key name') !== false || + strpos($msg, 'Duplicate table') !== false || + strpos($msg, 'already exists') !== false) { + continue; + } else { + throw $e; + } + } + } $applied++; } catch (Throwable $e) { - $msg = $e->getMessage(); - // Check if it's a common "already exists" error which we can safely ignore - if (strpos($msg, 'Duplicate column name') !== false || - strpos($msg, 'Duplicate key name') !== false || - strpos($msg, 'already exists') !== false) { - $applied++; - } else { - $errors[] = basename($file) . ": " . $msg; - } + $errors[] = basename($file) . ": " . $e->getMessage(); } } @@ -116,7 +127,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { header('Location: install.php?step=4'); exit; } else { - $error = "Applied $applied migrations, but some errors occurred:
"; + $error = "Applied migrations, but some errors occurred:
"; } } catch (Throwable $e) { $error = "Migration failed: " . $e->getMessage(); @@ -178,9 +189,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Installer

- - - + $i\n"; + endfor; ?>
@@ -194,23 +208,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {

Step 1: System Requirements

Next: Database Config - - - + Fix requirements to continue"; + endif; ?>
@@ -279,4 +293,4 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - + \ No newline at end of file