Koozali.org: home of the SME Server

Load Data Local Infile

Offline ajkeane

  • ****
  • 187
  • +0/-0
    • http://keane.co.nz
Load Data Local Infile
« 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
...

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Load Data Local Infile
« Reply #1 on: May 08, 2013, 10:14:05 AM »
Quote
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

Offline ajkeane

  • ****
  • 187
  • +0/-0
    • http://keane.co.nz
Re: Load Data Local Infile
« Reply #2 on: May 08, 2013, 11:39:06 AM »
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.
...

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Load Data Local Infile
« Reply #3 on: May 08, 2013, 11:51:12 AM »
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...