0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 18.226.34.148


Current Path : /var/www/html/rcub/src/
Upload File :
Current File : /var/www/html/rcub/src/export_import_utility.php

<?php
function ExportTablesFromDbtoSystem($aobj_context)
{	
	 $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
	$data_base_name=($aobj_context->mobj_db->database);//replace(storage_path,'\\','\\\\')
	$get_data="select table_name,
			 storage_path  
			from export_table_setup";		
	//echo $get_data; die();
	$lobj_get_data = $aobj_context->mobj_db->GetAll($get_data);echo mysql_error();  ;
 	foreach($lobj_get_data as $key=>$val)
	{
		$table_name=$val[table_name];
		$path=$val[storage_path];
		$path=str_replace("\\","\\\\",$path);
		$path.="\\\\".$table_name.".csv";
		$get_headers="select GROUP_CONCAT(\"'\",COLUMN_NAME,\"' as \" ,COLUMN_NAME) as header_cols from 
		information_schema.COLUMNS where TABLE_SCHEMA='{$data_base_name}'
		and TABLE_NAME='{$table_name}'";
		$lobj_get_headers = $aobj_context->mobj_db->GetRow($get_headers);
		$header_cols=$lobj_get_headers[header_cols];//select {$header_cols} union
		$export_data="  
						select * from {$table_name}  
					INTO OUTFILE '{$path}'
			FIELDS TERMINATED BY \",\" OPTIONALLY ENCLOSED BY \"\"\"\" LINES TERMINATED BY '\r\n'";
		$lobj_export_data = $aobj_context->mobj_db->Execute($export_data);
		 //echo $export_data;die();
		 /* $data=$export_data;
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
		return; */
		 
	}	
	if($lobj_export_data)
	{
		$data="Files Created Successfully";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
	 }
	 else
	 {
		$data="Error";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
	 } 
}	 
function importTablesFromSystemtoDb($aobj_context)
{	
	 $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	$get_data="select table_name,storage_path,				
				ifnull(is_delete,0) as is_delete 
				from import_table_setup";		
	$lobj_get_data = $aobj_context->mobj_db->GetAll($get_data);
 	foreach($lobj_get_data as $key=>$val)
	{
		$table_name=$val[table_name];
		if($val[is_delete]=='1')
		{
		$truncate_table="truncate table {$val[table_name]} ";
		$lobj_truncate_table = $aobj_context->mobj_db->Execute($truncate_table);
		}
		$path=$val[storage_path];
		$path=str_replace("\\","\\\\",$path);
		$path.="\\\\".$table_name.".csv";
		
		$import_data="load DATA INFILE '{$path}'
                      into table  {$table_name}					
			FIELDS TERMINATED BY \",\" OPTIONALLY ENCLOSED BY \"\"\"\" LINES TERMINATED BY '\r\n'
			";
		$lobj_import_data = $aobj_context->mobj_db->Execute($import_data);	
 	//IGNORE 1 LINES 
	}
	if($lobj_import_data)
	{
		$data="Data Imported Successfully";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
	 }
	 else
	 {
		$data="Error";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success");
	 } 
}

?>