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()); Quote 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(); Quote 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); Quote Link to comment https://forums.phpfreaks.com/topic/164095-read-file/#findComment-865638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.