11<?php
22class SQL_Backup {
33
4- private $ version = "1.0.6 " ;
4+ /*
5+
6+ GNU GENERAL PUBLIC LICENSE
7+ Version 3, 29 June 2007
8+
9+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
10+ Everyone is permitted to copy and distribute verbatim copies
11+ of this license document, but changing it is not allowed.
12+
13+ */
14+
15+ private $ version = "1.0.7 " ;
516 private $ site = "https://github.com/Chak10/Backup-SQL-By-Chak10.git " ;
617
718 var $ con ;
@@ -21,9 +32,6 @@ class SQL_Backup {
2132 var $ info_t ;
2233 var $ info = array ();
2334
24- const SQL = 13 ;
25- const CSV = 26 ;
26- const JSON = 49 ;
2735
2836 function __construct ($ con = null , $ table_name = null , $ folder = null , $ query_limit = null , $ compress = null , $ ext = null , $ alltable_in_file = null , $ save = null , $ sql_unique = null ) {
2937 $ this ->con = $ con ;
@@ -66,35 +74,21 @@ function execute() {
6674 $ tables = is_array ($ table_name ) ? $ table_name : explode (", " , $ table_name );
6775 }
6876 $ this ->del_csv != null ? $ del_c = $ this ->del_csv : $ del_c = ', ' ;
69- $ this ->enc_csv != null ? $ enc_c = $ this ->enc_csv : $ enc_c = '" ' ;
70- switch ($ this ->ext ) {
71- case self ::SQL :
72- $ save == true ? $ this ->sql_exec ($ con , $ tables , $ limit ) : $ this ->sql = $ this ->sql ($ con , $ tables , $ limit );
73- break ;
74- case self ::CSV :
75- $ save == true ? $ this ->csv_exec ($ con , $ tables , $ del_c , $ enc_c ) : $ this ->csv = $ this ->csv ($ con , $ tables , $ del_c , $ enc_c );
76- break ;
77- case self ::JSON :
78- $ save == true ? $ this ->json_exec ($ con , $ tables ) : $ this ->json = $ this ->json ($ con , $ tables );
79- break ;
80- case (self ::SQL + self ::CSV ):
81- $ save == true ? $ this ->sql_exec ($ con , $ tables , $ limit ) : $ this ->sql = $ this ->sql ($ con , $ tables , $ limit );
82- $ save == true ? $ this ->csv_exec ($ con , $ tables , $ del_c , $ enc_c ) : $ this ->csv = $ this ->csv ($ con , $ tables , $ del_c , $ enc_c );
83- break ;
84- case (self ::SQL + self ::JSON ):
85- $ save == true ? $ this ->sql_exec ($ con , $ tables , $ limit ) : $ this ->sql = $ this ->sql ($ con , $ tables , $ limit );
86- $ save == true ? $ this ->json_exec ($ con , $ tables ) : $ this ->json = $ this ->json ($ con , $ tables );
87- break ;
88- case (self ::JSON + self ::CSV ):
89- $ save == true ? $ this ->json_exec ($ con , $ tables ) : $ this ->json = $ this ->json ($ con , $ tables );
90- $ save == true ? $ this ->csv_exec ($ con , $ tables , $ del_c , $ enc_c ) : $ this ->csv = $ this ->csv ($ con , $ tables , $ del_c , $ enc_c );
91- break ;
92- default :
93- $ save == true ? $ this ->sql_exec ($ con , $ tables , $ limit ) : $ this ->sql = $ this ->sql ($ con , $ tables , $ limit );
94- $ save == true ? $ this ->json_exec ($ con , $ tables ) : $ this ->json = $ this ->json ($ con , $ tables );
95- $ save == true ? $ this ->csv_exec ($ con , $ tables , $ del_c , $ enc_c ) : $ this ->csv = $ this ->csv ($ con , $ tables , $ del_c , $ enc_c );
96- break ;
77+ $ this ->enc_csv != null ? $ enc_c = $ this ->enc_csv : $ enc_c = '' ;
78+ foreach ($ this ->ext as $ type_ext ) {
79+ switch ($ type_ext ) {
80+ case "sql " :
81+ $ save == true ? $ this ->sql_exec ($ con , $ tables , $ limit ) : $ this ->sql = $ this ->sql ($ con , $ tables , $ limit );
82+ break ;
83+ case "csv " :
84+ $ save == true ? $ this ->csv_exec ($ con , $ tables , $ del_c , $ enc_c ) : $ this ->csv = $ this ->csv ($ con , $ tables , $ del_c , $ enc_c );
85+ break ;
86+ case "json " :
87+ $ save == true ? $ this ->json_exec ($ con , $ tables ) : $ this ->json = $ this ->json ($ con , $ tables );
88+ break ;
89+ }
9790 }
91+
9892 }
9993
10094 }
@@ -208,7 +202,7 @@ private function json($con, $tables) {
208202 return $ forjson ;
209203 }
210204
211- private function csv ($ con , $ tables , $ del = ', ' , $ enc = '" ' ) {
205+ private function csv ($ con , $ tables , $ del = ', ' , $ enc = '' ) {
212206 if (is_array ($ tables ) === false )
213207 return false ;
214208 $ return = array ();
@@ -284,9 +278,9 @@ private function sql($con, $tables, $limit) {
284278 $ fields = '' ;
285279 while ($ field_info = $ result ->fetch_field ()) {
286280 $ fields .= "` " . $ field_info ->name . "`, " ;
287- $ db = $ field_info ->db ;
281+ $ db = $ field_info ->db ;
288282 }
289- $ fields = substr ($ fields , 0 , -1 );
283+ $ fields = substr ($ fields , 0 , -1 );
290284 $ return .= "-- Database: " . ($ db ) . $ nl . "-- " . $ nl ;
291285 $ this ->info_t === true ? $ this ->info [$ table ] = array (
292286 "R " => $ num_rows ,
@@ -421,22 +415,23 @@ private function checksep($s) {
421415 private function checkext ($ ext ) {
422416 if (!$ this ->res )
423417 return false ;
424- if (is_null ($ ext )) {
425- $ this ->ext = self ::SQL ;
426- } elseif (is_string ($ ext )) {
427- if (strpos ($ ext , ', ' ) === true ) {
428- $ ext = explode (', ' , $ ext );
429- $ this ->ext = array_sum ($ ext );
430- } else {
431- $ this ->ext = (int ) $ ext ;
432- }
418+ if (is_string ($ ext )) {
419+ $ ext = explode (', ' , strtolower ($ ext ));
433420 } elseif (is_array ($ ext )) {
434- $ this ->ext = array_sum ($ ext );
435- } elseif (is_int ($ ext )) {
421+ $ ext = array_map ('strtolower ' , $ ext );
422+ }
423+ if (in_array ("sql " , $ ext ) || in_array ("csv " , $ ext ) || in_array ("json " , $ ext )) {
436424 $ this ->ext = $ ext ;
425+ } elseif (in_array ("all " , $ ext )) {
426+ $ this ->ext = array (
427+ "sql " ,
428+ "csv " ,
429+ "json "
430+ );
437431 } else {
438- $ this ->err = -12 ;
439- $ this ->res = false ;
432+ $ this ->ext = array (
433+ "sql "
434+ );
440435 }
441436 }
442437
0 commit comments