Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a memory-friendly function that should be able to <strong>split a big file in individual queries without needing to open the whole file at once</strong>:</p> <pre><code>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 '&lt;h3&gt;ERROR: ' . $query . '&lt;/h3&gt;' . "\n"; } else { echo '&lt;h3&gt;SUCCESS: ' . $query . '&lt;/h3&gt;' . "\n"; } while (ob_get_level() &gt; 0) { ob_end_flush(); } flush(); } if (is_string($query) === true) { $query = array(); } } return fclose($file); } } return false; } </code></pre> <p>I tested it on a big phpMyAdmin SQL dump and it worked just fine.</p> <hr> <p><strong>Some test data:</strong></p> <pre><code>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; </code></pre> <p><strong>And the respective output:</strong></p> <pre><code>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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload