Forum Moderators: open
Thanks,
Steven.
I read somewhere that you have to use the absolute path to the file
Yes you need to call the file with the absolute path.
I have used this small php script to LOAD very large files into mysql database because of the limitations of phpmyadmin.
Hope this helps
<?php
// setup file and table
$source_file_01 = "/usr/home/sites/www.dotcom.net/web/data/tab_flatfile.txt";
$destination_table_01 = "db_table_name";
//call to function
$luinfo = load_file_data($source_file_01, $destination_table_01);
// LOAD DATA INFILE
// EMPTY TABLE BEFORE LOAD
function load_file_data($source_file, $destable){
// Connect to the DB
$db_host = "localhost";
$db_user = "#*$!x";
$db_pass = "#*$!#*$!";
$db_name = "#*$!#*$!x";
$connect = @mysql_connect($db_host,$db_user,$db_pass);
@mysql_select_db($db_name);
// Empty table
$query = "DELETE FROM $db_name.$destable";
$result = mysql_query($query);
// do the data import
$query = "LOAD DATA INFILE \"$source_file\" INTO TABLE $destable";
$result = mysql_db_query($db_name, $query, $connect)
or die(error_log ("Couldn't execute query \nINPUT FILE: $source_file \nTABLE: $destable \nERROR: ".mysql_error()."", 1,"webmaster@dotcom.net"));
}
?>
Thanks,
Steven.
Most likely password incorrect.
Link to mysql doc.
[dev.mysql.com...]
Best thing to do is echo the mysql error and track down the error number.
$feed = gzopen("path/filename.txt.gz","r");
$sql_1 = 'DELETE FROM example';
$sql_2 = 'OPTIMIZE TABLE example';
$sql_3 = "LOAD DATA LOCAL INFILE '$feed' INTO TABLE `example` FIELDS TERMINATED BY '¦' ENCLOSED BY '\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n\\r'";
$query_1 = mysql_query($sql_1) or die('query_1 no good. '.mysql_error());
$query_2 = mysql_query($sql_2) or die('query_2 no good. '.mysql_error());
$query_3 = mysql_query($sql_3) or die('query_3 no good. '.mysql_error()); I have no idea how to make this work and after searching for hours I can't find anything of use. Please help. Thanks,
Steven.
It might be that you have to uncompress the file to a temp file read that and then trash the temp file. From what I see size of the file and the time of execution can create a error.