Insert csv data in to Database

<?php
$conn=mysql_connect("localhost","<user>","<pass>") or die("unable to connect localhost".mysql_error());
$db=mysql_select_db("<database>",$conn) or die("unable to select db name");

$file=fopen("export.csv","r");
while(($var=fgetcsv($file,1000))!==FALSE)
{
$var2=$var[0];
$var1=explode(';',$var2);

print_r($var1);
if($var1[0] != 'id'){
$ro=mysql_query("SELECT <select.column> FROM <table> WHERE <column>=".$var1[1]);
$row1 = mysql_fetch_assoc($ro);
$ro1= mysql_num_rows($ro);
echo $ro1;

if($ro1<1){
mysql_query("INSERT INTO <table> (
`<column1>` ,
`<column2>` ,
`<column3>` ,
`<column4>`
)
VALUES (
NULL , ".$var1[1].", ".$var1[2].", ".$var1[3]."
);
");
}else{
mysql_query("UPDATE <table> SET  <column>= ". $var1[1].", <column> = ". $var1[2].", <column> = ". $var1[3]." WHERE <column> = ".$row1['<select.column>']);
}}
}
fclose($file);

?>

Tags: 
X