Dako Posted September 21, 2009 Share Posted September 21, 2009 Hello people. I have a problem and maybe you can help me =) I have to put a txt file into a table from my database. I can do it, if the file is in my computer. $cfile = "D:\creleases.txt"; $sql = mysql_query ("LOAD DATA INFILE 'newreleases.txt' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" ); exit("done"); But if i try a txt file from a webpage, i can't do it. For example: http://www.diamondcomics.com/shipping/newreleases.txt How can i do it? can you help me? please. thanks in advance Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/ Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 Is this SQL related? Either way, if remote files can not be used that way, maybe you need to read the file, create a new file on your own server, then do it that way? file() Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922120 Share on other sites More sharing options...
Dako Posted September 21, 2009 Author Share Posted September 21, 2009 yes, is SQL related. I already tried with file () and it didn't work. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922124 Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 Using this proccess? [*]file_get_contents() - get the text [*]fwrite() - to put string from above to new file [*]Use your sql query with file on own server Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922128 Share on other sites More sharing options...
Dako Posted September 21, 2009 Author Share Posted September 21, 2009 like this you say? $cfile = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt'); $txt = fwrite($cfile); $sql = mysql_query ("LOAD DATA INFILE '$txt' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" ); Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922132 Share on other sites More sharing options...
ozestretch Posted September 21, 2009 Share Posted September 21, 2009 fwrite() Need to open the file (as this is a weekly release, make a blank text file on your server, fopen() that file, then fwrite() the $cfile) then sql the file you wrote to. Next week, get new contents, open that file, write new data to it (as opposed to ammending), asql it again week after etc.. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922136 Share on other sites More sharing options...
Dako Posted September 21, 2009 Author Share Posted September 21, 2009 sorry for not reading =/ if i understand you correctly, this is what i have to do : $cfile = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true); $fp = fopen('creleases.txt', 'w'); fwrite ($fp, $cfile); fclose ($fp); $sql = mysql_query ("LOAD DATA INFILE '$fp' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" ); but it put nothing in the table. i guess i'm doing something wrong. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922615 Share on other sites More sharing options...
Dako Posted September 22, 2009 Author Share Posted September 22, 2009 i made something like this and it didn't work. I don't know what is the problem here. $file = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true); $fp = fopen('creleases.txt', 'w'); fwrite ($fp, $file); fclose($fp); $cfile = "http://localhost/creleases.txt"; $sql = mysql_query ("LOAD DATA INFILE '$cfile' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" ); it put nothing in the table. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922625 Share on other sites More sharing options...
knsito Posted September 22, 2009 Share Posted September 22, 2009 try LOAD DATA LOCAL INFILE ? btw, why not just ftp the file onto the server? Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922627 Share on other sites More sharing options...
MatthewJ Posted September 22, 2009 Share Posted September 22, 2009 Try $sql = mysql_query ("LOAD DATA INFILE 'newreleases.txt' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" ) or die (mysql_error()); and see if it maybe has a problem with the file. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922631 Share on other sites More sharing options...
Dako Posted September 22, 2009 Author Share Posted September 22, 2009 it doesn't "die", the program echo "done" like if it was all okay. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922658 Share on other sites More sharing options...
Dako Posted September 22, 2009 Author Share Posted September 22, 2009 if i put this: $file = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true); $fp = fopen('creleases.txt', 'w'); fwrite ($fp, $file); fclose($fp); $cfile = 'http://localhost/creleases.txt'; $sql = mysql_query ("LOAD DATA INFILE '$cfile' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" )or die (mysql_error()); i get this : File 'http:\\localhost\creleases.txt' not found (Errcode: 22) the file exists! i'm seeing it right now. Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922667 Share on other sites More sharing options...
Dako Posted September 22, 2009 Author Share Posted September 22, 2009 it works!! thank you very much. $file = file_get_contents ('http://www.diamondcomics.com/shipping/newreleases.txt', true); $fp = fopen('D:\comicreleases.txt', 'w'); fwrite ($fp, $file); fclose($fp); $cfile = "D:\comicreleases.txt"; $sql = mysql_query ("LOAD DATA INFILE '$cfile' INTO TABLE table_comic FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'" )or die (mysql_error()); $result = mysql_query("select * from table_comic WHERE precio = ''"); while($r=mysql_fetch_array($result)) { $fecha = $r["fecha"]; $producto = $r["producto"]; $precio = $r["precio"]; $id = $r["id"]; $del = "DELETE FROM table_comic WHERE id=$id"; $delete = mysql_query($del); } Link to comment https://forums.phpfreaks.com/topic/174965-txt-from-a-webpage-into-a-database/#findComment-922675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.