Location: PHPKode > scripts > User Info & GeoIP > user-info-geoip/helper.folder/installDatabase.php
<?php
/**************************************************/
/*
Released by AwesomePHP.com, under the GPL License, a
copy of it should be attached to the zip file, or
you can view it on http://AwesomePHP.com/gpl.txt
*/
/**************************************************/

/*
User Edits
*/

$hostName = 'localhost';
$userName = 'root';
$passWord = 'master';
$dataBase = 'test';
$fileLocation = 'GeoIPCountryWhois.csv';


/* End User Edits */

$connection = mysql_connect ($hostName, $userName, $passWord ) or die(mysql_error());
mysql_select_db($dataBase,$connection)  or $error = mysql_error();
if($error != NULL){ mysql_close($connection); die($error);}


/*
First query to create table
*/
$createTable = "CREATE TABLE `geo_ip` (
  `record_id` bigint(20) NOT NULL auto_increment,
  `begin_ip` varchar(25) NOT NULL default '',
  `end_ip` varchar(255) NOT NULL default '',
  `begin_num` bigint(20) NOT NULL default '0',
  `end_num` bigint(20) NOT NULL default '0',
  `iso_code` varchar(4) NOT NULL default '',
  `country_name` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`record_id`)
) COMMENT='Geo IP Table' ;";

if(!is_file('GeoIPCountryWhois.csv')){
	die('Unable to locate GeoIPCountryWhois.csv');
}

$file = fopen('GeoIPCountryWhois.csv','r');
if($file){
	mysql_query($createTable,$connection) or die(mysql_error());
	while($cont = fread($file,1026467)){
		$cvs_data .= $cont;
	}
	fclose($file);
	$lines = explode("\n",$cvs_data);
	$queryies = array();
	foreach($lines as $line){
		$cvs_info = explode(',',$line);
		foreach($cvs_info as $sub => $is){
			$cvs_info[$sub] = str_replace('"','',$is);
		}
		array_push($queryies,"INSERT INTO `geo_ip` 
			(`begin_ip`,`end_ip`,`begin_num`,`end_num`,`iso_code`,`country_name`) VALUES
			('$cvs_info[0]','$cvs_info[1]','$cvs_info[2]','$cvs_info[3]','$cvs_info[4]','".addslashes($cvs_info[5])."')");
		
	}
	mysql_query("TRUNCATE TABLE `geo_ip`");
	foreach($queryies as $query){
		$insert_record = mysql_query($query,$connection);
	}
	echo 'Done';
}
mysql_close($connection);
?>
Return current item: User Info & GeoIP