Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_url = 'pgsql://user:password@host/dbname';
- $conn = db_connect($db_url);
- $file = fopen("fileToImport.csv", "r");
- echo "Importing file....\n";
- echo "Let me a second...\n";
- while ($row = fgetcsv($file, 10000, ",") )
- {
- $luminario = $row[3];
- $tipo = $row[2];
- $numero = $row[1];
- $calle = $row[0];
- $result = pg_query($conn,"INSERT INTO googlemaps_data (tipo_luminaria,tipo_poste,poblado,calle,numero_poste) values ('{$luminario}', '{$tipo}','Mexico', '{$calle}', '{$numero}')");
- if (!$result) {
- echo "An error occured.\n";
- exit;
- }
- }
- fclose($file);
- echo "Importing Done...\n";
- function db_connect($url)
- {
- $url = parse_url($url);
- $conn_string = '';
- if (isset($url['user'])) {
- $conn_string .= ' user=' . urldecode($url['user']);
- }
- if (isset($url['pass'])) {
- $conn_string .= ' password=' . urldecode($url['pass']);
- }
- if (isset($url['host'])) {
- $conn_string .= ' host=' . urldecode($url['host']);
- }
- if (isset($url['path'])) {
- $conn_string .= ' dbname=' . substr(urldecode($url['path']), 1);
- }
- if (isset($url['port'])) {
- $conn_string .= ' port=' . urldecode($url['port']);
- }
- $connection = @pg_connect($conn_string);
- if (!$connection)
- {
- exit;
- }
- return $connection;
- }
- ?>
Add Comment
Please, Sign In to add comment