PHP Classes

MySQL importer: Execute SQL statements from MySQL dump files

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 954 All time: 3,777 This week: 488Up
Version License PHP version Categories
classmyqlimporter 2.0.1GNU General Publi...5Databases, Files and Folders


This class can be used to execute SQL statements read from MySQL dump files.

It connects to a given MySQL database using MySQLi, reads a given dump file, skips comment lines, and executes the SQL statements that are read from the file.

Picture of David Castillo
  Performance   Level  
Name: David Castillo <contact>
Classes: 1 package by
Country: Mexico Mexico
Age: 37
All time rank: 242728 in Mexico Mexico
Week rank: 216 Up1 in Mexico Mexico Up



include ("ClassMySQLImport.php");

$host = "localhost"; // database host (required)
$port = 3306; // database port (optional)
$dbUser = "root"; //database user (required)
$dbPassword = "mysql"; // database password (required)
$sqlFile = "SQLFileTest2.sql"; // Path to SQL file (required)

/* -------------------------------
** Initialize (basic usage):
** ------------------------------- */

$newImport = new MySQLImport($host, $dbUser, $dbPassword);
* And you can specify port
$newImport = new MySQLImport($host, $dbUser, $dbPassword, $port);

/* -------------------------------
** Start import (basic usage):
** ------------------------------- */
** 1) You can specify database.
** NOTE: This doesn't override the clause USE in the file, but sets an initial database.
$newImport->doImport($sqlFile, "initial_db_name");
** 2) You can create the database (if it doesn't exist).
$newImport->doImport($sqlFile, "initial_db_name", true);
** 3) You can drop the database and then create it.
$newImport->doImport($sqlFile, "initial_db_name", true, true);
** 4) Or just drop it.
$newImport->doImport($sqlFile, "initial_db_name", false, true);

// Check for errors
if ($newImport->hadErrors){
// Display errors
echo "<pre>\n";
} else {
"<strong>File imported successfully</strong>";


  Files folder image Files  
File Role Description
Files folder imageOLD_VERSION (2 files)
Plain text file ClassMySQLImport.php Class Main Class
Accessible without login Plain text file examples.php Example Examples of usage
Accessible without login Plain text file SQLFileToTest1.sql Data SQL File Example with Errors
Accessible without login Plain text file SQLFileToTest2.sql Data SQL File Example without Errors

  Files folder image Files  /  OLD_VERSION  
File Role Description
  Accessible without login Plain text file example.php Example OLD Example of usage
  Plain text file ClassSQLimporter.php Class OLD Main Class

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:3,777
This week:488Up
User Ratings User Comments (2)
 All time
That's a very good class
8 years ago (David Hernandez)
That's a good class !! loool
15 years ago (Josť Filipe Lopes Santos)