Import a MySQL database using PHP

How can I import MySQL database using PHP? Also if you have to import large size of MySQL dump, how do you import it easily? In this article is describing how to import MySQL database using PHP.In this method you can save your time instead of you import sql file in the phpmyadmin or database software.As my personal experience I tested this script using 2.125GB large database dump file.

1-First create a database and user. Assign user to the database.
2-Copy and paste the following php scripts and insert your database,users details to the variables.

3-Keep the database dump file in to the same directory.
4-Also keep the phpMyImporterClass.php file.
5-Run the import.php file.

If you run the large size of database file, remember increase the max_execution_time and memory_limit values in the server(If you are running on the local server change it in the php.ini file and restart the server).

That’s only.After execution the result will be displayed on the import.php file.

How can I import zip or gz format file?

Simply change the code like this.

Download Import a MySQL database using PHP Example(4 KB)

Published by

Sumith Harshan

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.