PHP Classes

MySQL importer: Execute SQL statements from MySQL dump files

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

Author

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  

 

Example

<?php

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):
** ------------------------------- */
$newImport->doImport($sqlFile);
/*
** 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";
   
print_r($newImport->errors);
    echo
"\n</pre>";
} else {
    echo
"<strong>File imported successfully</strong>";
}


?>


  Files folder image Files (6)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:954
This week:0
All time:3,778
This week:488Up
User Ratings User Comments (2)
 All time
Utility:87%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:-
Examples:68%StarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1402
 
That's a very good class
9 years ago (David Hernandez)
70%StarStarStarStar
That's a good class !! loool
16 years ago (José Filipe Lopes Santos)
70%StarStarStarStar