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 Quote 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 Quote 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? Quote 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()); } ?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.