Holdorf.dk/Software

Software Development Blog

phpMyImporter released

For many months, I wanted to be able to import backups of databases created by my other project, phpMyDumper, without using phpMyAdmin. The php configuration limits the filesize that phpMyAdmin can import. By default the filesize limit is 2 MB, which is potentially a problem if you are not able to change the php configuration, eg when using an external webhost.

I wrote this php class entirely from scratch my self and it does not have a filesize limit since it reads the file directly from the file directory. I also added progress information, so its easy to see when it is finish importing the sql file. It also supports compressed sql files created by phpMyDumper and phpMyAdmin and more importantly, it has support for UTF-8 connections to the MySQL datasbase.

Using the php class is straight forward if you have used phpMyDumper. Normally you will be using the php class from command line when you import one of your database backups. The example below shows how to use the phpMyImporter class. Have fun!

<?php
/*
* phpMyImporter
* -------------
* Version: 1.00
* Copyright (c) 2009 by Micky Holdorf
* Holdorf.dk/Software - micky.holdorf@gmail.com
* GNU Public License http://opensource.org/licenses/gpl-license.php
*
*/


@include_once('phpMyImporter.php');

$dbhost = "localhost";
$dbuser = "user";
$dbpass = "password";
$dbname = "database";

$path      = "backup/";
$filename  = $path."dump.sql"; // Filename of dump, default: dump.sql
$compress  = false; // Import gz compressed file, default: false

$connection = @mysql_connect($dbhost,$dbuser,$dbpass);
$dump = new phpMyImporter($dbname,$connection,$filename,$compress);

$dump->utf8 = true; // Uses UTF8 connection with MySQL server, default: true

$dump->doImport();
?>

Comments are closed.