papaface Posted June 6, 2007 Share Posted June 6, 2007 Hello, How would I run a query for each line in a text file? I have this so far but it doesnt work: <?php mysql_connect("localhost","xxx","xxx") or die (mysql_error()); mysql_select_db("xxxx") or die (mysql_error()); $filename = "file.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); foreach($contents as $line_num => $line) { mysql_query("insert into cats (category) values ('{$line}')") or die(mysql_error()); } ?> Link to comment https://forums.phpfreaks.com/topic/54373-solved-run-a-query-for-each-line/ Share on other sites More sharing options...
papaface Posted June 6, 2007 Author Share Posted June 6, 2007 Got it working. Thanks Link to comment https://forums.phpfreaks.com/topic/54373-solved-run-a-query-for-each-line/#findComment-268883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.