Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 541409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:20:25+00:00 2026-05-13T10:20:25+00:00

I have a situation where I have to update a web site on a

  • 0

I have a situation where I have to update a web site on a shared hosting provider. The site has a CMS. Uploading the CMS’s files is pretty straightforward using FTP.

I also have to import a big (relative to the confines of a PHP script) database file (Around 2-3 MB uncompressed). Mysql is closed for access from the outside, so I have to upload a file using FTP, and start a PHP script to import it. Sadly, I do not have access to the mysql command line function so I have to parse and query it using native PHP. I also can’t use LOAD DATA INFILE. I also can’t use any kind of interactive front-end like phpMyAdmin, it needs to run in an automated fashion. I also can’t use mysqli_multi_query().

Does anybody know or have a already coded, simple solution that reliably splits such a file into single queries (there could be multi-line statements) and runs the query. I would like to avoid to start fiddling with it myself due to the many gotchas that I’m likely to come across (How to detect whether a field delimiter is part of the data; how to deal with line breaks in memo fields; and so on). There must be a ready made solution for this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:20:25+00:00Added an answer on May 13, 2026 at 10:20 am

    Here is a memory-friendly function that should be able to split a big file in individual queries without needing to open the whole file at once:

    function SplitSQL($file, $delimiter = ';')
    {
        set_time_limit(0);
    
        if (is_file($file) === true)
        {
            $file = fopen($file, 'r');
    
            if (is_resource($file) === true)
            {
                $query = array();
    
                while (feof($file) === false)
                {
                    $query[] = fgets($file);
    
                    if (preg_match('~' . preg_quote($delimiter, '~') . '\s*$~iS', end($query)) === 1)
                    {
                        $query = trim(implode('', $query));
    
                        if (mysql_query($query) === false)
                        {
                            echo '<h3>ERROR: ' . $query . '</h3>' . "\n";
                        }
    
                        else
                        {
                            echo '<h3>SUCCESS: ' . $query . '</h3>' . "\n";
                        }
    
                        while (ob_get_level() > 0)
                        {
                            ob_end_flush();
                        }
    
                        flush();
                    }
    
                    if (is_string($query) === true)
                    {
                        $query = array();
                    }
                }
    
                return fclose($file);
            }
        }
    
        return false;
    }
    

    I tested it on a big phpMyAdmin SQL dump and it worked just fine.


    Some test data:

    CREATE TABLE IF NOT EXISTS "test" (
        "id" INTEGER PRIMARY KEY AUTOINCREMENT,
        "name" TEXT,
        "description" TEXT
    );
    
    BEGIN;
        INSERT INTO "test" ("name", "description")
        VALUES (";;;", "something for you mind; body; soul");
    COMMIT;
    
    UPDATE "test"
        SET "name" = "; "
        WHERE "id" = 1;
    

    And the respective output:

    SUCCESS: CREATE TABLE IF NOT EXISTS "test" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT, "description" TEXT );
    SUCCESS: BEGIN;
    SUCCESS: INSERT INTO "test" ("name", "description") VALUES (";;;", "something for you mind; body; soul");
    SUCCESS: COMMIT;
    SUCCESS: UPDATE "test" SET "name" = "; " WHERE "id" = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do a data update using Oracle. I have a situation where
Lets imagine my situation (it's fake, of course)... I have web-site that have 1000
I have a situation where I need to update a control referenced in a
Common situation: I have a client on my server who may update some of
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
I have a very unique situation. We use a Cisco Web VPN (don't know
Here's my situation. I have a web forms page, and it's getting annoying when
update Here is the situation: I'm working on a website that has no physical
The situation is as follows: Method1 has four database update methods in it. The
UPDATE : I got my O3D situation straightened out, but I have yet to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.