Export structure and data (e.g. in PhpMyAdmin)

I want to export data and structure from a MySQL database using PHP. I know about the SELECT INTO OUTFILE , but I want to have a file similar to the one created by PhpMyAdmin in the export window, so everything is CREATE TABLE and INSERT INTO .

HDo do you know how phpMyAdmn generates these files? I was looking at the code, and I found the SELECT INTO OUTFILE command in it. But I'm not sure if this command is used to create this structure. Is there another command for this, or is the exported file created manually using table schema information?

+6
php mysql export phpmyadmin
source share
3 answers

You can do this using SHOW CREATE TABLE .

+7
source share

I created a php script to backup mysql tables (data only). this will export mysql data to sql file which is fully compatible with phpmyadmin import

Maybe this will help you

backup mysql script data in php: http://dl.dropbox.com/u/18434517/mysql_backup.php

+4
source share

Here you can find a comprehensive solution for dumping mysql structure and data, such as PMA (and without using exec, passthru, etc.):

https://github.com/antarasi/MySQL-Dump-with-Foreign-keys

This is a dszymczuk project plug with my improvements.

Simple use

 <?php //MySQL connection parameters $dbhost = 'localhost'; $dbuser = 'dbuser'; $dbpsw = 'pass'; $dbname = 'dbname'; //Connects to mysql server $connessione = @mysql_connect($dbhost,$dbuser,$dbpsw); //Set encoding mysql_query("SET CHARSET utf8"); mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'"); //Includes class require_once('FKMySQLDump.php'); //Creates a new instance of FKMySQLDump: it exports without compress and base-16 file $dumper = new FKMySQLDump($dbname,'fk_dump.sql',false,false); $params = array( //'skip_structure' => TRUE, //'skip_data' => TRUE, ); //Make dump $dumper->doFKDump($params); ?> 

works like a charm :-)

+2
source share

All Articles