Koozali.org: home of the SME Server
Contribs.org Forums => General Discussion => Topic started by: ajkeane on May 08, 2013, 05:12:19 AM
-
Hi
I am trying to upload a csv file onto my server and then truncate a table and load the data using a php script that uses mysql load data local file but cannot get this to work. Does anyone know if there is a db command or anything that I need to enable to get this to work?
Thanks
Tony
-
cannot get this to work
we have no evidence/log to help you and AFAIK there's nothing that you can do via db commands..
finally, this has nothing to do with SME itself and should moved to General Discussion
-
Just in case anyone else is interested in doing this the code that works is this.
<?php
$MySqlHostname = "localhost";
$MySqlUsername = "UserName";
$MySqlPassword = "PassWord";
$MySqlDatabase = "DataBasename";
$dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) OR DIE("Unable to connect to database");
@mysql_select_db("$MySqlDatabase") or die( "Unable to select database");
mysql_query("LOAD DATA LOCAL INFILE 'path to/CSVFile.csv' REPLACE INTO TABLE `tablename` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'");
?>
My issue turned out to be due to file paths though I was seeing no errors in the logs.
-
well, without the real 'path to/CSVfile.csv' we can't help you more.. I mean, if you don't tell us what it was and what it is now...