[nycphp-talk] Zip webservice 0.1
Jayesh Sheth
jayeshsh at ceruleansky.com
Tue Apr 5 12:17:40 EDT 2005
Hello all,
I have an interesting followup question. I tried importing the
aforementioned zip code data into MySQL using PHPMyAdmin, but it took
over 5 minutes, and the script timed out.
I did the same using a PHP script run from the command line (using the
CLI version of PHP) and it seemed to take but a few seconds (okay, maybe
20 seconds) to insert 43191 rows.
The CLI import script follows. Does anyone know why PHPMyAdmin's import
process takes so much longer?
Thanks,
- Jay Sheth
<?php
// PHP Command Line script to import the all data from zipcodes.mysql
into your database
/*
Usage:
On the command line -
c:\php4cli\php-cli.exe
C:\your_comp\zipcodes\zipcodes_mysql\import_zip_cli.php
Remember to delete the last empty line from zipcode.mysql before running
this script. Also, this script assumes that you have created the
zipcodes table before hand, and have removed everything but the INSERT
statements in the zipcodes.mysql file.
*/
$link = mysql_connect('localhost', 'root', '');
if (!$link)
{
exit('Could not connect: ' . mysql_error());
}
mysql_select_db('zipcodes');
echo "Connected successfully \n";
echo "Loading file lines into array ... \n";
$lines = file("C:\\your_comp\\zipcodes\\zipcodes_mysql\\zipcodes.mysql");
echo "Finished loading file lines into array ... \n";
echo "Inserting data ... \n";
$num_lines = count($lines);
for ($i = 1; $i <= $num_lines; $i++)
{
$result = mysql_query( $lines[$i] );
if (! $result)
{
exit("Error: could not read query at line $i :" . $lines[$i] . "
. Exiting.");
}
}
echo "Finished importing data ... All done. $num_lines rows were
inserted. Goodbye. \n";
mysql_close($link);
?>
More information about the talk
mailing list