update db connection for production and add init_db.php
This commit is contained in:
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
$host = 'localhost';
|
$host = getenv('DB_HOST') ?: 'localhost';
|
||||||
$db = 'webgis_bansos';
|
$db = getenv('DB_NAME') ?: 'webgis_bansos';
|
||||||
$user = 'root';
|
$user = getenv('DB_USER') ?: 'root';
|
||||||
$pass = ''; // Default XAMPP password is empty
|
$pass = getenv('DB_PASS') ?: '';
|
||||||
$charset = 'utf8mb4';
|
$charset = 'utf8mb4';
|
||||||
|
|
||||||
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db.php';
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
CREATE TABLE IF NOT EXISTS features (
|
||||||
|
id VARCHAR(100) PRIMARY KEY,
|
||||||
|
layer VARCHAR(50) NOT NULL,
|
||||||
|
data JSON NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_layer ON features(layer);
|
||||||
|
";
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo->exec($sql);
|
||||||
|
echo "Database table 'features' created successfully.";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error creating table: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user