Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env php
- <?php
- // TODO
- /*
- *
- * check if the file exists and is readable
- * fopen on the file name
- * once the file is open
- * use fgetcsv to read the file's lines in a loop into an array
- * use CS50::query to read each line into the database using INSERT IGNORE
- * once we are done fclose to close the file
- */
- require('../includes/config.php');
- if($argc == 2)
- {
- $fileName = $argv[1];
- if( file_exists($argv[1]) && is_readable($argv[1]) )
- {
- $addressFile = fopen($fileName, "r");
- $placeLine = [];
- while( $placeLine = fgetcsv($addressFile, 200 , "\t") !== false )
- {
- $queryString = 'INSERT IGNORE INTO places (country_code, postal_code, place_name, admin_name1, admin_code1, admin_name2, admin_code2, admin_name3, admin_code3, latitude,longitude, accuracy)';
- $queryString .= ' VALUES(?,?,?,?,?,?,?,?,?,?,?,?)';
- CS50::query("${queryString}", $placeLine[0], $placeLine[1], $placeLine[2],$placeLine[3],$placeLine[4],$placeLine[5],$placeLine[6],$placeLine[7], $placeLine[8], $placeLine[9],$placeLine[10],$placeLine[11]);
- }
- fclose($addressFile);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement