dreamwest Posted June 29, 2009 Share Posted June 29, 2009 Im trying import a txt file line by line Heres the txt file: one two three four five etc... Basically i want to import this into my database: $file_names = '/home/htdocs/file_names.txt'; $sql = "INSERT INTO `forum` SET `username`='ghost' "; $result = mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/164095-read-file/ Share on other sites More sharing options...
MasterACE14 Posted June 29, 2009 Share Posted June 29, 2009 you can use file_get_contents(); Link to comment https://forums.phpfreaks.com/topic/164095-read-file/#findComment-865630 Share on other sites More sharing options...
everisk Posted June 29, 2009 Share Posted June 29, 2009 If you want to read line by line you can $fd = fopen ($file_names, "r"); while (!feof ($fd)) { $buffer = fgets($fd, 1024); $sql = "INSERT INTO `forum` SET `username`='$buffer' "; $result = mysql_query($sql) or die(mysql_error()); } fclose ($fd); Link to comment https://forums.phpfreaks.com/topic/164095-read-file/#findComment-865638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.