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 This week: 1All time: 3,776 This week: 560Up
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  
Name: David Castillo <contact>
Classes: 1 package by
Country: Mexico Mexico
Age: 37
All time rank: 242728 in Mexico Mexico
Week rank: 416 Up8 in Mexico Mexico Up

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  
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  
 0%
Total:954
This week:1
All time:3,776
This week:560Up
User Ratings User Comments (2)
 All time
Utility:87%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:-
Examples:68%StarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1372
 
That's a very good class
8 years ago (David Hernandez)
70%StarStarStarStar
That's a good class !! loool
15 years ago (José Filipe Lopes Santos)
70%StarStarStarStar