Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    MySQL file parsing

    How could I use PHP to execute all statements in an SQL file?

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,775
    Thanks
    19
    Thanked 155 Times in 146 Posts
    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...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •