dakke Posted December 30, 2009 Share Posted December 30, 2009 I have a sql file locally, which I try to import in my db. I pasted it into a txt file, though I assume that I can use the sql file as well... I try to do the following: $file = file_get_contents("includes/database.txt") or exit ("Unable to get content file!"); $query = preg_split("/;/", $file) or exit ("Unable to split content file!"); foreach($connection as $query) { $sql = $query; $execute = mysql_query($sql, $connection) or exit ("Unable to execute file!"); } However, nothing happens. Can someone enlighten me, who is extremely limited in php and just starting to learn it all. Link to comment https://forums.phpfreaks.com/topic/186669-foreach-loop-on-sql-file-does-not-work/ Share on other sites More sharing options...
trq Posted December 30, 2009 Share Posted December 30, 2009 The problem is your foreach loop is incorrect, but we'll clean up the code a little anyway. $file = file_get_contents("includes/database.txt"); $queries = explode(";", $file); foreach ($queries as $query) { mysql_query($query); } Link to comment https://forums.phpfreaks.com/topic/186669-foreach-loop-on-sql-file-does-not-work/#findComment-985846 Share on other sites More sharing options...
dakke Posted December 30, 2009 Author Share Posted December 30, 2009 That did it! Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/186669-foreach-loop-on-sql-file-does-not-work/#findComment-985852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.