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 && isset($argv[1]))
- {
- $fileName = $argv[1];
- if(file_exists($fileName) && is_readable($fileName))
- {
- $addressFile = fopen($argv[1], "r");
- if($addressFile == NULL)
- {
- exit(1);
- }
- $queryString = "INSERT 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(?,?,?,?,?,?,?,?,?,?,?,?)";
- $loopCounter = 0;
- $placeLine = [];
- while($placeLine = fgetcsv($addressFile, 1000 , "\t") !== FALSE)
- {
- /* if(count($placeLine) > 0)
- *{
- * foreach ($placeLine as $pLine)
- * {
- * $queryString .= $pLine . ',';
- * }
- * }
- * $queryString .= ')';
- */
- // 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]);
- }
- }
- }
- else
- {
- print("usage: \./import /path/to/US.txt");
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement