SQL File Importer PHP

Overview

The SQL File Importer is a PHP-based utility designed to import one or more SQL files directly into an existing MySQL database using WampServer.

It is particularly useful for importing large SQL files that may exceed the normal PHP memory or browser upload limits.

The importer reads SQL files directly from a local Windows folder, processing them line by line rather than loading the entire file into memory.

It provides progress updates, error reporting and a final summary of the import process.

Key Features

•Import individual or multiple files: Select a single SQL file or import all SQL files from a chosen Windows folder.

•Automatic file detection: Automatically identifies and lists available .sql files in the selected folder.

•Large file support: Reads files directly from the local drive, avoiding browser upload limits and reducing memory usage.

•Automatic SQL execution: Executes the SQL statements contained within each file, including instructions to create tables, insert data and modify database structures.

•Sequential processing: When importing multiple files, processes them individually in filename order.

•Progress monitoring: Displays import progress and the number of SQL statements executed.

•Error handling: Reports SQL errors and stops processing if an error occurs.

•Import summary: Displays the total number of files processed, SQL statements executed, errors encountered and overall processing time.

Instructions for Use

Step 1 – Prepare the SQL Files

Place the SQL files you wish to import into a folder on your local Windows computer.

For example:

C:\Data\SQL_Files\

Ensure that all files have the .sql extension.

Important: When importing multiple SQL files, they will be processed in filename order. If the files have dependencies, ensure their filenames reflect the required processing sequence.

Step 2 – Launch the SQL Importer

Open the SQL File Importer PHP utility through your local WampServer web browser environment.

The Enter SQL Import Parameters screen will appear.

Step 3 – Enter the Database Identifier

In the Database Identifier field, enter the name of the MySQL database into which the SQL files will be imported.

For example:

0_import_temp

Important: The database must already exist. The importer does not automatically create the destination database.

Step 4 – Select the Windows Folder

In the Windows Folder field, enter or paste the full Windows folder path containing the SQL files.

For example:

C:\Data\SQL_Files\

The importer automatically scans the folder and displays the number of SQL files found.

The SQL file selection dropdown is automatically updated whenever the folder path changes.

Step 5 – Select the SQL Files

Use the SQL File dropdown to select either:

•An individual SQL file – Imports only the selected file.

•All SQL files (entire folder) – Imports every SQL file found in the specified Windows folder.

When importing multiple files, each file is processed individually before moving to the next.

Step 6 – Start the Import

Once all required fields have been completed, the Launch button becomes active and flashes red and white.

Click Launch to begin importing the selected SQL files.

The importer reads each file directly from the Windows folder and executes its SQL statements against the selected database.

Step 7 – Monitor the Import

During processing, the importer displays:

•The name and size of the SQL file being imported.

•Import progress as a percentage.

•The number of SQL statements successfully executed.

•Any SQL errors encountered.

Progress updates are generated every 1,000 lines processed.

Important: If an SQL error occurs, the importer stops processing the current file and does not continue with any remaining files.

Step 8 – Review the Import Summary

Once processing has finished, the importer displays a summary for each processed file, including:

•Number of SQL statements executed.

•Number of errors encountered.

•Whether the file was successfully processed.

A Final Import Summary is also displayed, showing:

•Total files processed.

•Total SQL statements executed.

•Total errors.

•Script start date and time.

•Script completion date and time.

•Total processing time.

Important Notes

Existing Tables and Data

The importer executes the SQL statements exactly as defined within the selected files.

If those statements contain instructions to drop, replace or modify existing tables, the existing database structures or data may be affected.

Large SQL Files

Large SQL files may take some time to process. The importer is designed to reduce memory usage by reading files line by line and avoids the browser's normal file upload limits.

SQL Errors

The importer is configured to stop when an SQL error occurs. Statements successfully executed before the error are not automatically reversed.

MySQL Database

The destination MySQL database must exist before launching the importer.

Local File Access

SQL files must be stored in a Windows folder accessible to the WampServer PHP environment.

Summary

The SQL File Importer provides a straightforward method for importing individual or multiple SQL files into an existing MySQL database, particularly when handling large database exports.

Its automatic file detection, sequential processing, progress monitoring and error reporting make it suitable for routine database imports and data management tasks.



Topic last reviewed: 19/10/26