Importing CSV data into MySQL table
Posted: Wed Oct 01, 2008 1:39 pm
I am creating a script so I can fill a MySQL table, from a CSV file created in Excel.
The CSV contains this:
The MySQL table has the following fields:
When I run the import.php, I get the "Error, query failed" error. Anyone knows what I am doing wrong?
Also, by the way, does anyone know how to encrypt an Excel column? (With MD5 encryption). For example, for the passwords column. I need it to be encrypted.
The CSV contains this:
Code: Select all
"1","Dirk Breeuwer","d78c03d72e72b44a131d255aec3c8a11","0","00:00:00",
"2","Pedro","d78c03d72e72b44a131d255aec3c8a11","0","00:00:00
"3","Javier","d78c03d72e72b44a131d255aec3c8a11","0","00:00:00",- ID, username, password, voted, time, partido
Code: Select all
<?php
//database variables
$dbHost = "localhost";
$dbUser = "*******";
$dbPass = "*****";
$dbDatabase = "******";
//conect to database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$query = "LOAD DATA INFILE 'users.csv' INTO TABLE users FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
(ID, username, password, voted, time, partido)";
mysql_query($query) or die ('Error, query failed');
?> Also, by the way, does anyone know how to encrypt an Excel column? (With MD5 encryption). For example, for the passwords column. I need it to be encrypted.