View Full Version : MySQL file parsing
09-15-2005, 10:56 PM
How could I use PHP to execute all statements in an SQL file?
09-15-2005, 11:38 PM
if it's raw SQL, the you would need to open the text file (with the SQL in it) with a PHP filesystem function and the read the contents of the file into a variable...let's say each SQL command is distinguished by a new line break...so then you use the explode function to separate your file content variable into parts, using '\r\n\' as your separator...now you have an array with each SQL command as one unique element....then you just iterate thru your array and use PHP's mysql functions to systematically execute each sql command (each command is an array element)...
well that's how I would approach it... ;)
09-15-2005, 11:55 PM
That is how I am currently doing it. I was hoping that there was some as yet undiscovered (at least by me, anyway) method of doing it such as with MySQL's "source" command.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.