29 lines
1.0 KiB
PHP
29 lines
1.0 KiB
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
// Sample data representing a CSV file of Indian railway stations.
|
|
// In a real-world scenario, this would be read from a file e.g., using fgetcsv.
|
|
$station_data = [
|
|
['SBC', 'KSR BENGALURU', 12.9716, 77.5946],
|
|
['NDLS', 'NEW DELHI', 28.6139, 77.2090],
|
|
['BCT', 'MUMBAI CENTRAL', 18.9688, 72.8203],
|
|
['HWH', 'HOWRAH JN', 22.5831, 88.3411],
|
|
['MAS', 'CHENNAI CENTRAL', 13.0827, 80.2707],
|
|
['NZM', 'HAZRAT NIZAMUDDIN', 28.5888, 77.2520]
|
|
];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO stations (station_code, station_name, latitude, longitude) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE station_name=VALUES(station_name), latitude=VALUES(latitude), longitude=VALUES(longitude)");
|
|
|
|
foreach ($station_data as $row) {
|
|
$stmt->execute($row);
|
|
}
|
|
|
|
echo "Successfully seeded stations table with " . count($station_data) . " records.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
die("Database seeding failed: " . $e->getMessage() . "\n");
|
|
}
|
|
|