Created
June 30, 2011 15:58
-
-
Save krikulis/1056535 to your computer and use it in GitHub Desktop.
CSV => MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$host = ""; | |
$user = ""; | |
$pass = ""; | |
$file = "" | |
$link = mysql_connect($host, $user, $pass); | |
mysql_query("set names utf8;"); | |
mysql_query("USE truevision"); | |
$file = file_get_contents($file); | |
$file = explode("\n", $file); | |
function escape($var){ | |
$var = trim($var, '"' ); | |
return mysql_real_escape_string($var); | |
} | |
foreach($file as $line){ | |
$line = explode(",", $line); | |
$q = "INSERT INTO ip2countries (`ip_from`, `ip_to`, `from`, `to`, `code`, `country`) | |
VALUES ('" . escape($line[0]). " ', '" . escape($line[1]) . "', '" . escape($line[2]) . "', '" . escape($line[3]) . "', '" . escape($line[4]) . "', '" . escape($line[5]) ."');"; | |
$res = mysql_query($q); | |
if(!$res){ | |
die(mysql_error()); | |
} | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment