So I have a CSV generated from gmail exporting contacts and I need to be able to manage them. I need to get some of the values and pass them to MySQL database, I know how to do that once I got the data but I don't know how to store the data to do that. Hope I explained it correctly, and please keep in mind that I'm a totally noob programmer.
所以我有一个从gmail导出联系人生成的CSV,我需要能够管理它们。我需要获取一些值并将它们传递给MySQL数据库,我知道如何获取数据,但我不知道如何存储数据来做到这一点。希望我能正确解释,请记住,我是一个完全没人的程序员。
That's an example of the file:
这是该文件的一个示例:
Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,E-mail 1 - Type,E-mail 1 - Value,E-mail 2 - Type,E-mail 2 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value,Phone 3 - Type,Phone 3 - Value Firstname Lastname1 Lastname2,Firstname,Lastname1,Lastname2,,,,,,,,,,,,,,,,,,,,,,,GROUP ::: * My Contacts,* Work,EMAIL@hotmail.com,,,Mobile,679999999,,,, Firstname Lastname1 Lastname2,Firstname,Lastname1,Lastname2,,,,,,,,,,,,,,,,,,,,,,,GROUP ::: * My Contacts,* Work,email@gmail.com,,,Mobile,679999999,,,,
1 个解决方案
#1
i wont give you the answer, but this code will help you
我不会给你答案,但这段代码会帮助你
$file = fopen("google.csv","r")or die("file dont exist");
while (!feof($file )){
$data= fgetcsv($file,4096,",");
//insert to db
$loadsql = "INSERT INTO temporal_table(id,state,etc) VALUES ('$data[0]','$data[1]','etc');";
//where $data[n] is 1 data in a line of your csv file, in this case $data[0] is Name
mysql_query($loadsql) or die(mysql_error());
}
fclose($file );
#1
i wont give you the answer, but this code will help you
我不会给你答案,但这段代码会帮助你
$file = fopen("google.csv","r")or die("file dont exist");
while (!feof($file )){
$data= fgetcsv($file,4096,",");
//insert to db
$loadsql = "INSERT INTO temporal_table(id,state,etc) VALUES ('$data[0]','$data[1]','etc');";
//where $data[n] is 1 data in a line of your csv file, in this case $data[0] is Name
mysql_query($loadsql) or die(mysql_error());
}
fclose($file );