note 35958 deleted from function.fgetcsv by felipe
| From: | felipe@php.net | Date: | Sun, 10 Feb 2008 13:32:59 +0000 |
| Subject: | note 35958 deleted from function.fgetcsv by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135982@lists.php.net to get a copy of this message | ||
Note Submitter: chery79 at hushmail dot com
----
inserting IP-to-Country Database into mysql
<?
//CREATE TABLE
ip2country (
// id int(25) NOT NULL default '0',
// ipFrom int(15) NOT NULL default '0',
// ipTo int(15) NOT NULL default '0',
// country2 char(2) NOT NULL default '',
// country3 char(3) NOT NULL default '',
// country varchar(25) NOT NULL default ''
//) TYPE=MyISAM;
$link = mysql_connect("localhost", "username", "password") or
die("Could not connect: ".mysql_error());
// username = user account name
// password = password to user acc
$db = mysql_select_db("ip2country") or die(mysql_error());
// ip2country table is define on top
$row = 1;
$handle = fopen ("ip-to-country.csv","r");
// ip-to-country.csv must be in the same directory with this php file
while ($data = fgetcsv ($handle, 1000, ",")) {
$query = "INSERT INTO ip2country(id, ipFrom, ipTo,
country2, country3, country) VALUES('".
$row."', '".$data[0]."', '".$data[1]."',
'".$data[2]."', '".$data[3]."',
'".$data[4]."')";
$result = mysql_query($query) or die("Invalid query: " .
mysql_error().__LINE__.__FILE__);
$row++;
}
fclose ($handle);
?>