This tutorial is specific to MySQL as it relies on MySQL utilities like mysqldump. Other database provide similar utilities, for instance with SQL Server you can use osql.exe. Here are some examples:
http://stackoverflow...erver-databases
Export
Insert a new button into any of your app pages, name it 'Export DB' or similar.
In ClientAfter event use the following code:
location.href="export_db.php";
Other events should be empty.
Import
Insert a button name 'Run Import' where you need it to be.
ClientBefore code:
params["fname"] = $("#import_fname").val();
$("#form_import").submit();
Server code:
$result["txt"] = $params["fname"];
ClientAfter code:
if(result["txt"])
{
ctrl.setMessage("Imported successfully");
}
else
{
ctrl.setMessage("Choose a file to import");
}
Insert 'PHP code snippet' next to 'Run import' button and add the following code there:
echo "<div style='margin: 5px 10px;'><form name='form_import' id='form_import' target='iframe_import' method='post' action='import_db.php' enctype='multipart/form-data'>
<b>Select *.sql file to import</b>
<input type=file name=import_fname id=import_fname>
</form>
</div>
<iframe id=iframe_import name=iframe_import style='display:none'></iframe>";
To run the import you need to select the import file first and then click 'Run Import' button.
Files
In the output directory create file named export_db.php and put the following code there:
<?php
include("include/dbcommon.php");
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");
global $host,$user,$pwd, $sys_dbname;
ob_start();
$path = "c:\\xampp\\mysql\\bin\\mysqldump.exe";
$command = $path." ".$sys_dbname." --add-drop-table --host=$host --user=$user ";
if ($pwd)
$command.= "--password=". $pwd ." ";
system($command);
$dump = ob_get_contents();
ob_end_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($sys_dbname . "_" . date("Y-m-d_H-i-s").".sql"));
flush();
echo $dump;
exit();
?>
Create file named import_db.php and put the following code there:
<?php
include("include/dbcommon.php");
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");
global $host,$user,$pwd,$sys_dbname;
$path = "c:\\xampp\\mysql\\bin\\mysql.exe";
$command = $path." ".$sys_dbname." < ".$_FILES['import_fname']['tmp_name']." --host=$host --user=$user ";
if ($pwd)
$command.= "--password=". $pwd ." ";
echo system($command);
?>
إرسال تعليق