Welcome Guest, Not a member yet? Register   Sign In
How to import csv file to mysql
#4

[eluser]Near[/eluser]
Hi thanks for the help. i managed to insert the contents of csv files into mySQL using this query.

Code:
$fcontents = file('./uploads/'.$filename);
for($i=0;$i<sizeof($fcontents); $i++)
{
$line = trim($fcontents[$i]);
$arr = explode(",",$line);
$sql = "INSERT INTO user(name,id) VALUES ('".implode("','",$arr)."')";
$result = mysql_query($sql);
                                    
if(mysql_error())
                        
{
$flag = 2;
return $flag;
return $filename;
die('upload failed');
                            
}
    
}
else
{
$flag = 2;
return $flag;
}


Messages In This Thread
How to import csv file to mysql - by El Forum - 07-29-2011, 08:42 PM
How to import csv file to mysql - by El Forum - 07-30-2011, 01:27 AM
How to import csv file to mysql - by El Forum - 08-06-2011, 09:28 AM
How to import csv file to mysql - by El Forum - 08-08-2011, 03:13 AM
How to import csv file to mysql - by El Forum - 08-08-2011, 03:14 AM
How to import csv file to mysql - by El Forum - 08-08-2011, 12:59 PM
How to import csv file to mysql - by El Forum - 08-08-2011, 11:54 PM
How to import csv file to mysql - by El Forum - 08-09-2011, 02:13 AM
How to import csv file to mysql - by El Forum - 08-09-2011, 05:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB