just having a backup of the libraries Admin/vendor (angularjs & some libraries) api/system (codeigniter framework libraries) Student/vendor (angularjs & some libraries) api/application/third_party (two heavy useless libraries)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

90 lines
3.2 KiB

<?php
/*CAUTION .... any move could break the whole thing, no exception handeling provided, dbad*/
/*This whole file was inspired by eligant dump by phpmyadmin */
/*Here is how the whole thing implemented*/
/*followed export interface with its input to export.php in phpmyadmin */
/*next, tried to imitate only the conserned stuff*/
/* added the needed functions in the process from libraries to the class */
/**
* PhpMyAdmin stuff
*/
/*DO NOT MODIFY ORDER MATTERS*/
class PMA_stuff
{
function __construct($tables=array(),$db='test',$username = 'root',$password = '')
{
$_POST['table_select'] = $_POST['table_structure'] = $_POST['table_data'] = $tables;
$_POST['db']=$db;
$_POST['username'] = $username;
$_POST['password'] = $password;
$this->init_input();
}
private function init_input()
{
$pma_post = ["export_type" => "database", "export_method"=> "quick", "quick_or_custom"=> "quick", "what"=> "sql", "structure_or_data_forced"=> "0", "output_format"=> "sendit", "filename_template" =>"@DATABASE@", "charset"=> "utf-8","compression"=> "none", "codegen_structure_or_data"=> "data", "codegen_format"=> "0", "sql_include_comments"=> "something", "sql_compatibility"=> "NONE", "sql_structure_or_data"=> "structure_and_data", "sql_create_table"=> "something", "sql_auto_increment"=> "something", "sql_create_view"=> "something", "sql_procedure_function"=> "something", "sql_create_trigger"=> "something", "sql_backquotes"=> "something", "sql_type"=> "INSERT", "sql_insert_syntax"=> "both", "sql_max_query_size"=> "50000", "sql_hex_for_binary"=> "something", "sql_utc_time"=> "something"];
$_POST = array_merge($_POST,$pma_post);
}
public function export()
{
//revise phpmyadmin/export.php, this mha_export is a revised version of it.
include 'mha_export.php';
global $dump_buffer;
return $dump_buffer;
}
}
class PhpMAExport {
var $PMA = null;
public function __construct($tables,$db,$username ,$password )
{
$this->PMA = new PMA_stuff($tables,$db,$username ,$password);
}
private function optimize($dump_string){
/*\-\-.*\n ''*/
/*\n\n \n*/
///**/ ''
//$dump_string = preg_replace("~\n--.*\n~", "", $dump_string);
$statements = explode(";\n", $dump_string);
$res['create'] = [];
$res['data'] =[];
$res['alter'] = [];
foreach ($statements as $sql ) {
//$sql = preg_replace("~\n~", "", $sql);
// if( strpos($sql,'\n') ===0 || strpos($sql,'--') ===0 ){
// continue;
// }
// else
if(strpos($sql,'INSERT') !== FALSE){
$res['data'][] = $sql;
}elseif(strpos($sql,'CREATE') !== FALSE ){
/*CREATE TABLE */
//extract table name
$pos1 = strpos($sql, '`');
$pos2 = strpos($sql, '`', $pos1 + 1);
if(strpos($sql,'Database:')){
$pos1 = strpos($sql, '`',$pos2 + 1);
$pos2 = strpos($sql, '`', $pos1+1);
}
//$res['create'][] = 'DROP TABLE IF EXISTS ' . substr($sql, 13,strpos($sql,'(')-13).'; ' ;
$res['create'][] = 'DROP TABLE IF EXISTS ' . substr($sql, $pos1,$pos2-$pos1).'`; ' ;
$res['create'][] = $sql;
}elseif(strpos($sql, 'ALTER') !== FALSE){
$res['alter'][] = $sql;
}
}
return $res;
}
function export(){
$dump_buffer = $this->PMA->export();
return $this->optimize($dump_buffer);
}
}