papaface Posted May 30, 2007 Share Posted May 30, 2007 Hello, I have a .txt file that has the code to create tables etc in a database. How can I just load that into the database rather than having to type out it all manually in PHP? regards Link to comment https://forums.phpfreaks.com/topic/53544-load-sql-file-into-db/ Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 Use PHPMyAdmin if you have it Link to comment https://forums.phpfreaks.com/topic/53544-load-sql-file-into-db/#findComment-264599 Share on other sites More sharing options...
papaface Posted May 30, 2007 Author Share Posted May 30, 2007 No. I mean how can I get it to run through PHP but without me having to put the SQL in PHP mysql_query(""); Is there some way to load the file and then get PHP to execute it on the database? Link to comment https://forums.phpfreaks.com/topic/53544-load-sql-file-into-db/#findComment-264601 Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 If each query is on a separate line: <?php $lines = file("file.txt"); foreach($lines as $linenumber => $line) { $query = mysql_query($line) or die("Error on query $linenumber: ".mysql_error()); } ?> Link to comment https://forums.phpfreaks.com/topic/53544-load-sql-file-into-db/#findComment-264604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.