2006-08-20 21:15:47 +02:00
< ? php
2015-12-17 21:10:14 +01:00
/* Copyright ( C ) 2006 - 2014 Laurent Destailleur < eldy @ users . sourceforge . net >
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2006-08-20 21:15:47 +02:00
*
2011-10-15 20:45:16 +02:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2011-10-15 20:45:16 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
2006-08-20 21:15:47 +02:00
/**
2009-03-09 13:38:22 +01:00
* \file htdocs / admin / tools / export . php
2009-09-29 19:14:52 +02:00
* \brief Page to export a database into a dump file
2009-03-09 13:38:22 +01:00
*/
2006-08-20 21:15:47 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
2016-03-29 14:52:27 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/utils.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
2006-08-20 21:15:47 +02:00
$langs -> load ( " admin " );
2012-04-10 08:44:43 +02:00
$action = GETPOST ( 'action' , 'alpha' );
$what = GETPOST ( 'what' , 'alpha' );
$export_type = GETPOST ( 'export_type' , 'alpha' );
$file = GETPOST ( 'filename_template' , 'alpha' );
2006-08-20 21:15:47 +02:00
2012-04-10 08:44:43 +02:00
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
2012-10-13 14:47:46 +02:00
$page = GETPOST ( " page " , 'int' );
2012-02-10 10:53:11 +01:00
if ( ! $sortorder ) $sortorder = " DESC " ;
if ( ! $sortfield ) $sortfield = " date " ;
if ( $page < 0 ) { $page = 0 ; }
2018-04-21 12:16:12 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2012-02-10 10:53:11 +01:00
$offset = $limit * $page ;
if ( ! $user -> admin ) accessforbidden ();
2006-08-20 21:15:47 +02:00
2009-03-09 13:38:22 +01:00
if ( $file && ! $what )
2006-08-20 21:15:47 +02:00
{
2011-10-14 16:02:18 +02:00
//print DOL_URL_ROOT.'/dolibarr_export.php';
header ( " Location: " . DOL_URL_ROOT . '/admin/tools/dolibarr_export.php?msg=' . urlencode ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " ExportMethod " ))));
exit ;
2006-08-20 21:15:47 +02:00
}
2016-06-25 15:16:32 +02:00
$errormsg = '' ;
2006-08-20 21:15:47 +02:00
2008-08-03 13:34:47 +02:00
/*
2012-02-10 10:53:11 +01:00
* Actions
*/
2008-08-03 13:34:47 +02:00
2012-02-10 11:09:34 +01:00
if ( $action == 'delete' )
{
2014-03-31 00:19:31 +02:00
$file = $conf -> admin -> dir_output . '/' . GETPOST ( 'urlfile' );
2012-07-29 16:11:52 +02:00
$ret = dol_delete_file ( $file , 1 );
2015-10-23 12:58:30 +02:00
if ( $ret ) setEventMessages ( $langs -> trans ( " FileWasRemoved " , GETPOST ( 'urlfile' )), null , 'mesgs' );
else setEventMessages ( $langs -> trans ( " ErrorFailToDeleteFile " , GETPOST ( 'urlfile' )), null , 'errors' );
2012-07-29 15:47:24 +02:00
$action = '' ;
2012-02-10 11:09:34 +01:00
}
2006-08-24 20:51:59 +02:00
2012-02-10 10:53:11 +01:00
/*
* View
*/
2006-08-24 20:51:59 +02:00
2015-05-18 20:33:02 +02:00
$_SESSION [ " commandbackuplastdone " ] = '' ;
$_SESSION [ " commandbackuptorun " ] = '' ;
$_SESSION [ " commandbackupresult " ] = '' ;
2012-02-10 10:53:11 +01:00
// Increase limit of time. Works only if we are not in safe mode
2011-03-05 02:53:20 +01:00
$ExecTimeLimit = 600 ;
2012-02-10 10:53:11 +01:00
if ( ! empty ( $ExecTimeLimit ))
{
2011-03-05 02:53:20 +01:00
$err = error_reporting ();
error_reporting ( 0 ); // Disable all errors
//error_reporting(E_ALL);
@ set_time_limit ( $ExecTimeLimit ); // Need more than 240 on Windows 7/64
error_reporting ( $err );
2010-08-21 22:16:52 +02:00
}
2017-06-26 09:20:16 +02:00
$MemoryLimit = 0 ;
2012-02-10 10:53:11 +01:00
if ( ! empty ( $MemoryLimit ))
{
2011-03-05 02:53:20 +01:00
@ ini_set ( 'memory_limit' , $MemoryLimit );
2006-08-20 21:15:47 +02:00
}
2012-02-10 10:53:11 +01:00
$form = new Form ( $db );
$formfile = new FormFile ( $db );
2015-04-03 17:17:02 +02:00
//$help_url='EN:Backups|FR:Sauvegardes|ES:Copias_de_seguridad';
//llxHeader('','',$help_url);
2012-02-10 10:53:11 +01:00
2015-09-24 18:33:48 +02:00
//print load_fiche_titre($langs->trans("Backup"),'','title_setup');
2012-02-10 10:53:11 +01:00
2006-08-20 21:15:47 +02:00
// Start with empty buffer
$dump_buffer = '' ;
$dump_buffer_len = 0 ;
2012-02-10 10:53:11 +01:00
// We will send fake headers to avoid browser timeout when buffering
2006-08-20 21:15:47 +02:00
$time_start = time ();
2016-01-31 14:58:04 +01:00
$outputdir = $conf -> admin -> dir_output . '/backup' ;
$result = dol_mkdir ( $outputdir );
2016-03-29 14:52:27 +02:00
$utils = new Utils ( $db );
2009-10-26 04:10:12 +01:00
// MYSQL
2006-08-20 21:15:47 +02:00
if ( $what == 'mysql' )
{
2017-06-26 09:20:16 +02:00
2016-09-08 11:05:47 +02:00
$cmddump = GETPOST ( " mysqldump " ); // Do not sanitize here with 'alpha', will be sanitize later by dol_sanitizePathName and escapeshellarg
$cmddump = dol_sanitizePathName ( $cmddump );
2017-06-26 09:20:16 +02:00
2016-06-25 15:16:32 +02:00
if ( ! empty ( $dolibarr_main_restrict_os_commands ))
{
$arrayofallowedcommand = explode ( ',' , $dolibarr_main_restrict_os_commands );
$ok = 0 ;
dol_syslog ( " Command are restricted to " . $dolibarr_main_restrict_os_commands . " . We check that on of this command is inside " . $cmddump );
foreach ( $arrayofallowedcommand as $allowedcommand )
{
if ( preg_match ( '/' . preg_quote ( $allowedcommand , '/' ) . '/' , $cmddump ))
{
$ok = 1 ;
break ;
}
}
if ( ! $ok )
{
$errormsg = $langs -> trans ( 'CommandIsNotInsideAllowedCommands' );
}
}
2017-06-26 09:20:16 +02:00
2016-06-25 15:16:32 +02:00
if ( ! $errormsg && $cmddump )
2011-10-14 16:02:18 +02:00
{
dolibarr_set_const ( $db , 'SYSTEMTOOLS_MYSQLDUMP' , $cmddump , 'chaine' , 0 , '' , $conf -> entity );
}
2017-06-26 09:20:16 +02:00
if ( ! $errormsg )
2016-06-25 15:16:32 +02:00
{
$utils -> dumpDatabase ( GETPOST ( 'compression' , 'alpha' ), $what , 0 , $file );
$errormsg = $utils -> error ;
$_SESSION [ " commandbackuplastdone " ] = $utils -> result [ 'commandbackuplastdone' ];
$_SESSION [ " commandbackuptorun " ] = $utils -> result [ 'commandbackuptorun' ];
}
2011-10-14 16:02:18 +02:00
}
2016-03-29 14:52:27 +02:00
// MYSQL NO BIN
2011-10-14 16:02:18 +02:00
if ( $what == 'mysqlnobin' )
{
2016-03-29 14:52:27 +02:00
$utils -> dumpDatabase ( GETPOST ( 'compression' , 'alpha' ), $what , 0 , $file );
2015-04-03 17:17:02 +02:00
2016-03-29 14:52:27 +02:00
$errormsg = $utils -> error ;
$_SESSION [ " commandbackuplastdone " ] = $utils -> result [ 'commandbackuplastdone' ];
$_SESSION [ " commandbackuptorun " ] = $utils -> result [ 'commandbackuptorun' ];
2009-10-26 04:10:12 +01:00
}
// POSTGRESQL
if ( $what == 'postgresql' )
{
2016-09-08 11:05:47 +02:00
$cmddump = GETPOST ( " postgresqldump " ); // Do not sanitize here with 'alpha', will be sanitize later by dol_sanitizePathName and escapeshellarg
$cmddump = dol_sanitizePathName ( $cmddump );
2017-06-26 09:20:16 +02:00
2016-06-25 15:16:32 +02:00
if ( ! $errormsg && $cmddump )
2011-10-14 16:02:18 +02:00
{
dolibarr_set_const ( $db , 'SYSTEMTOOLS_POSTGRESQLDUMP' , $cmddump , 'chaine' , 0 , '' , $conf -> entity );
}
2017-06-26 09:20:16 +02:00
if ( ! $errormsg )
2016-06-25 15:16:32 +02:00
{
$utils -> dumpDatabase ( GETPOST ( 'compression' , 'alpha' ), $what , 0 , $file );
$errormsg = $utils -> error ;
$_SESSION [ " commandbackuplastdone " ] = $utils -> result [ 'commandbackuplastdone' ];
$_SESSION [ " commandbackuptorun " ] = $utils -> result [ 'commandbackuptorun' ];
}
2016-03-29 14:52:27 +02:00
$what = '' ; // Clear to show message to run command
2006-08-20 21:15:47 +02:00
}
2009-10-26 04:10:12 +01:00
2016-01-31 14:58:04 +01:00
if ( $errormsg )
{
setEventMessages ( $langs -> trans ( " Error " ) . " : " . $errormsg , null , 'errors' );
2009-10-26 04:10:12 +01:00
2016-01-31 14:58:04 +01:00
$resultstring = '' ;
$resultstring .= '<div class="error">' . $langs -> trans ( " Error " ) . " : " . $errormsg . '</div>' ;
2015-05-18 20:33:02 +02:00
2016-01-31 14:58:04 +01:00
$_SESSION [ " commandbackupresult " ] = $resultstring ;
}
else
{
if ( $what )
{
setEventMessages ( $langs -> trans ( " BackupFileSuccessfullyCreated " ) . '.<br>' . $langs -> trans ( " YouCanDownloadBackupFile " ), null , 'mesgs' );
$resultstring = '<div class="ok">' ;
$resultstring .= $langs -> trans ( " BackupFileSuccessfullyCreated " ) . '.<br>' ;
$resultstring .= $langs -> trans ( " YouCanDownloadBackupFile " );
$resultstring .= '<div>' ;
2015-05-18 20:33:02 +02:00
$_SESSION [ " commandbackupresult " ] = $resultstring ;
2016-01-31 14:58:04 +01:00
}
2017-11-25 01:58:11 +01:00
/* else
2015-04-03 17:17:02 +02:00
{
2017-11-25 01:58:11 +01:00
setEventMessages ( $langs -> trans ( " YouMustRunCommandFromCommandLineAfterLoginToUser " , $dolibarr_main_db_user , $dolibarr_main_db_user ), null , 'warnings' );
} */
2016-01-31 14:58:04 +01:00
}
2006-08-20 21:15:47 +02:00
2015-04-03 17:17:02 +02:00
/*
2012-02-10 10:53:11 +01:00
$filearray = dol_dir_list ( $conf -> admin -> dir_output . '/backup' , 'files' , 0 , '' , '' , $sortfield ,( strtolower ( $sortorder ) == 'asc' ? SORT_ASC : SORT_DESC ), 1 );
2012-02-10 11:09:34 +01:00
$result = $formfile -> list_of_documents ( $filearray , null , 'systemtools' , '' , 1 , 'backup/' , 1 , 0 ,( $langs -> trans ( " NoBackupFileAvailable " ) . '<br>' . $langs -> trans ( " ToBuildBackupFileClickHere " , DOL_URL_ROOT . '/admin/tools/dolibarr_export.php' )), 0 , $langs -> trans ( " PreviousDumpFiles " ));
2009-03-09 13:38:22 +01:00
2006-08-20 21:15:47 +02:00
print '<br>' ;
2015-04-03 17:17:02 +02:00
*/
2006-08-20 21:15:47 +02:00
2015-04-03 17:17:02 +02:00
// Redirect t backup page
header ( " Location: dolibarr_export.php " );
2006-08-20 21:15:47 +02:00
2015-04-03 17:17:02 +02:00
$time_end = time ();
2011-10-14 16:02:18 +02:00
$db -> close ();
// MYSQL NO BINARIES (only php)
/** Backup the db OR just a table without mysqldump binary ( does not require any exec permission )
* Author : David Walsh ( http :// davidwalsh . name / backup - mysql - database - php )
* Updated and enhanced by Stephen Larroque ( lrq3000 ) and by the many commentators from the blog
2012-08-15 18:35:37 +02:00
* Note about foreign keys constraints : for Dolibarr , since there are a lot of constraints and when imported the tables will be inserted in the dumped order , not in constraints order , then we ABSOLUTELY need to use SET FOREIGN_KEY_CHECKS = 0 ; when importing the sql dump .
* Note2 : db2SQL by Howard Yeend can be an alternative , by using SHOW FIELDS FROM and SHOW KEYS FROM we could generate a more precise dump ( eg : by getting the type of the field and then precisely outputting the right formatting - in quotes , numeric or null - instead of trying to guess like we are doing now ) .
*
2011-10-14 16:02:18 +02:00
* @ param string $outputfile Output file name
* @ param string $tables Table name or '*' for all
* @ return int < 0 if KO , > 0 if OK
*/
function backup_tables ( $outputfile , $tables = '*' )
{
global $db , $langs ;
global $errormsg ;
// Set to UTF-8
2017-12-03 11:45:34 +01:00
if ( is_a ( $db , 'DoliDBMysqli' )) {
2015-12-17 21:10:14 +01:00
/** @var DoliDBMysqli $db */
$db -> db -> set_charset ( 'utf8' );
} else {
/** @var DoliDB $db */
$db -> query ( 'SET NAMES utf8' );
$db -> query ( 'SET CHARACTER SET utf8' );
}
2011-10-14 16:02:18 +02:00
//get all of the tables
if ( $tables == '*' )
{
$tables = array ();
$result = $db -> query ( 'SHOW FULL TABLES WHERE Table_type = \'BASE TABLE\'' );
while ( $row = $db -> fetch_row ( $result ))
{
$tables [] = $row [ 0 ];
}
}
else
{
$tables = is_array ( $tables ) ? $tables : explode ( ',' , $tables );
}
//cycle through
$handle = fopen ( $outputfile , 'w+' );
2018-04-16 13:51:16 +02:00
if ( fwrite ( $handle , '' ) === false )
2011-10-14 16:02:18 +02:00
{
$langs -> load ( " errors " );
dol_syslog ( " Failed to open file " . $outputfile , LOG_ERR );
$errormsg = $langs -> trans ( " ErrorFailedToWriteInDir " );
return - 1 ;
}
2011-10-15 20:45:16 +02:00
// Print headers and global mysql config vars
$sqlhead = '' ;
2016-11-26 17:48:06 +01:00
$sqlhead .= " -- " . $db :: LABEL . " dump via php with Dolibarr " . DOL_VERSION . "
2011-10-15 20:45:16 +02:00
--
-- Host : " . $db->db ->host_info. " Database : " . $db->database_name . "
-- ------------------------------------------------------
-- Server version " . $db->db ->server_info. "
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */ ;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */ ;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */ ;
/*!40101 SET NAMES utf8 */ ;
2017-12-03 11:45:34 +01:00
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */ ;
/*!40103 SET TIME_ZONE='+00:00' */ ;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */ ;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */ ;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */ ;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */ ;
2012-08-16 16:02:08 +02:00
2011-10-15 20:45:16 +02:00
" ;
2012-08-16 16:02:08 +02:00
if ( GETPOST ( " nobin_disable_fk " )) $sqlhead .= " SET FOREIGN_KEY_CHECKS=0; \n " ;
2017-12-03 11:45:34 +01:00
//$sqlhead .= "SET SQL_MODE=\"NO_AUTO_VALUE_ON_ZERO\";\n";
2012-08-16 16:02:08 +02:00
if ( GETPOST ( " nobin_use_transaction " )) $sqlhead .= " SET AUTOCOMMIT=0; \n START TRANSACTION; \n " ;
2011-10-15 20:45:16 +02:00
fwrite ( $handle , $sqlhead );
2012-08-16 16:02:08 +02:00
$ignore = '' ;
if ( GETPOST ( " nobin_sql_ignore " )) $ignore = 'IGNORE ' ;
$delayed = '' ;
if ( GETPOST ( " nobin_delayed " )) $delayed = 'DELAYED ' ;
2011-10-15 20:45:16 +02:00
// Process each table and print their definition + their datas
2011-10-14 16:02:18 +02:00
foreach ( $tables as $table )
{
2011-10-15 20:45:16 +02:00
// Saving the table structure
2012-08-16 16:02:08 +02:00
fwrite ( $handle , " \n -- \n -- Table structure for table ` " . $table . " ` \n -- \n " );
2011-10-14 16:02:18 +02:00
2012-08-16 16:02:08 +02:00
if ( GETPOST ( " nobin_drop " )) fwrite ( $handle , " DROP TABLE IF EXISTS ` " . $table . " `; \n " ); // Dropping table if exists prior to re create it
2017-12-03 11:45:34 +01:00
fwrite ( $handle , " /*!40101 SET @saved_cs_client = @@character_set_client */; \n " );
fwrite ( $handle , " /*!40101 SET character_set_client = utf8 */; \n " );
2011-10-14 16:02:18 +02:00
$resqldrop = $db -> query ( 'SHOW CREATE TABLE ' . $table );
$row2 = $db -> fetch_row ( $resqldrop );
2014-03-31 00:19:31 +02:00
if ( empty ( $row2 [ 1 ]))
{
fwrite ( $handle , " \n -- WARNING: Show create table " . $table . " return empy string when it should not. \n " );
2011-10-14 16:02:18 +02:00
}
2014-03-31 00:19:31 +02:00
else
{
fwrite ( $handle , $row2 [ 1 ] . " ; \n " );
//fwrite($handle,"/*!40101 SET character_set_client = @saved_cs_client */;\n\n");
// Dumping the data (locking the table and disabling the keys check while doing the process)
fwrite ( $handle , " \n -- \n -- Dumping data for table ` " . $table . " ` \n -- \n " );
if ( ! GETPOST ( " nobin_nolocks " )) fwrite ( $handle , " LOCK TABLES ` " . $table . " ` WRITE; \n " ); // Lock the table before inserting data (when the data will be imported back)
if ( GETPOST ( " nobin_disable_fk " )) fwrite ( $handle , " ALTER TABLE ` " . $table . " ` DISABLE KEYS; \n " );
2017-12-03 11:45:34 +01:00
else fwrite ( $handle , " /*!40000 ALTER TABLE ` " . $table . " ` DISABLE KEYS */; \n " );
2014-08-01 00:53:29 +02:00
2014-03-31 00:19:31 +02:00
$sql = 'SELECT * FROM ' . $table ;
$result = $db -> query ( $sql );
2014-08-01 00:53:29 +02:00
while ( $row = $db -> fetch_row ( $result ))
2014-03-31 00:19:31 +02:00
{
// For each row of data we print a line of INSERT
fwrite ( $handle , 'INSERT ' . $delayed . $ignore . 'INTO `' . $table . '` VALUES (' );
$columns = count ( $row );
for ( $j = 0 ; $j < $columns ; $j ++ ) {
// Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier)
2016-05-08 12:32:18 +02:00
if ( $row [ $j ] == null && ! is_string ( $row [ $j ])) {
2014-03-31 00:19:31 +02:00
// IMPORTANT: if the field is NULL we set it NULL
$row [ $j ] = 'NULL' ;
2015-02-03 13:05:28 +01:00
} elseif ( is_string ( $row [ $j ]) && $row [ $j ] == '' ) {
2014-03-31 00:19:31 +02:00
// if it's an empty string, we set it as an empty string
$row [ $j ] = " '' " ;
2015-02-03 13:05:28 +01:00
} elseif ( is_numeric ( $row [ $j ]) && ! strcmp ( $row [ $j ], $row [ $j ] + 0 ) ) { // test if it's a numeric type and the numeric version ($nb+0) == string version (eg: if we have 01, it's probably not a number but rather a string, else it would not have any leading 0)
2014-03-31 00:19:31 +02:00
// if it's a number, we return it as-is
2014-12-28 20:12:32 +01:00
// $row[$j] = $row[$j];
2014-03-31 00:19:31 +02:00
} else { // else for all other cases we escape the value and put quotes around
$row [ $j ] = addslashes ( $row [ $j ]);
$row [ $j ] = preg_replace ( " # \n # " , " \\ n " , $row [ $j ]);
$row [ $j ] = " ' " . $row [ $j ] . " ' " ;
}
}
fwrite ( $handle , implode ( ',' , $row ) . " ); \n " );
}
if ( GETPOST ( " nobin_disable_fk " )) fwrite ( $handle , " ALTER TABLE ` " . $table . " ` ENABLE KEYS; \n " ); // Enabling back the keys/index checking
if ( ! GETPOST ( " nobin_nolocks " )) fwrite ( $handle , " UNLOCK TABLES; \n " ); // Unlocking the table
fwrite ( $handle , " \n \n \n " );
}
2011-10-14 16:02:18 +02:00
}
2014-08-01 00:53:29 +02:00
2011-10-14 16:02:18 +02:00
/* Backup Procedure structure*/
/*
2011-10-15 20:45:16 +02:00
$result = $db -> query ( 'SHOW PROCEDURE STATUS' );
2011-10-14 16:02:18 +02:00
if ( $db -> num_rows ( $result ) > 0 )
{
2011-10-15 20:45:16 +02:00
while ( $row = $db -> fetch_row ( $result )) { $procedures [] = $row [ 1 ]; }
foreach ( $procedures as $proc )
{
fwrite ( $handle , " DELIMITER $ $\n\n " );
fwrite ( $handle , " DROP PROCEDURE IF EXISTS ' $name '.' $proc ' $ $\n " );
$resqlcreateproc = $db -> query ( " SHOW CREATE PROCEDURE ' $proc ' " );
$row2 = $db -> fetch_row ( $resqlcreateproc );
fwrite ( $handle , " \n " . $row2 [ 2 ] . " $ $\n\n " );
fwrite ( $handle , " DELIMITER ; \n \n " );
}
2011-10-14 16:02:18 +02:00
}
*/
/* Backup Procedure structure*/
2011-10-15 20:45:16 +02:00
// Write the footer (restore the previous database settings)
2012-08-16 16:02:08 +02:00
$sqlfooter = " \n \n " ;
if ( GETPOST ( " nobin_use_transaction " )) $sqlfooter .= " COMMIT; \n " ;
if ( GETPOST ( " nobin_disable_fk " )) $sqlfooter .= " SET FOREIGN_KEY_CHECKS=1; \n " ;
$sqlfooter .= " \n \n -- Dump completed on " . date ( 'Y-m-d G-i-s' );
2011-10-15 20:45:16 +02:00
fwrite ( $handle , $sqlfooter );
2011-10-14 16:02:18 +02:00
fclose ( $handle );
return 1 ;
}