note 35958 added to function.fgetcsv

From: Date: Sat, 20 Sep 2003 18:18:40 +0000
Subject: note 35958 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-56817@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35958 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35958&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35958&report=yes

« previous php.notes (#56817) next »