Created
December 9, 2019 02:07
-
-
Save AgungPambudi/aab5e35d83ff9b65f5af7ad68a1edf3f to your computer and use it in GitHub Desktop.
php script to get the lists of mysqldump on windows or mac/linux.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
| title : mysqldump_list_using_array.php | |
| description : php script to get the lists of mysqldump on windows or mac/linux. | |
| author : Agung Pambudi | |
| website : http://agungpambudi.com | |
| email : [email protected] | |
| source : https://www.php.net/manual/en/index.php, https://www.php.net/manual/en/function.array-merge.php | |
| _ _ _ | |
| ___ ___ _ _ ___ ___ ___ ___ _____| |_ _ _ _| |_| ___ ___ _____ | |
| | .'| . | | | | . | . | .'| | . | | | . | |_| _| . | | | |
| |__,|_ |___|_|_|_ | _|__,|_|_|_|___|___|___|_|_|___|___|_|_|_| | |
| |___| |___|_| | |
| | |
| | |
*/ | |
function mysqldump_list() { | |
// check if current operating system is windows | |
// and check if glob function is exists | |
// echo (function_exists('glob')) ? 'glob function is available' : 'glob function is not available'; | |
if ('win' == strtolower(substr(PHP_OS, 0, 3)) && function_exists('glob')) { | |
$drives = array('C', 'D', 'E', 'F'); | |
// determine whether a variable is empty using empty() function | |
if (!empty($_SERVER['DOCUMENT_ROOT'])) { | |
// get the drive that this is running on | |
$current_drive = strtoupper(substr($_SERVER['DOCUMENT_ROOT'], 0, 1)); | |
// checks if a value from $current_drive variable exists in an $drives array using in_array() | |
if (!in_array($current_drive, $drives)) array_unshift($drives, $current_drive); | |
// array_unshift function (append data and put on the first list) | |
// $queue = array("university", "college"); | |
// array_unshift($queue, "lecturer", "degree"); | |
// Array | |
// ( | |
// [0] => lecturer | |
// [1] => degree | |
// [2] => university | |
// [3] => college | |
// ) | |
} | |
$directories = array(); | |
foreach ($drives as $drive_letter) { | |
// glob() function searches all pathnames based on pattern | |
$dir = glob("$drive_letter:\\{Apps\\AppServ\\{,MySQL*,etc}{,\\bin,\\?},mysqldump}\\mysqldump*", GLOB_BRACE); | |
// check if $dir variable is an array using is_array() | |
if (is_array($dir)) $directories = array_merge($directories, $dir); | |
// array_merge() function is to use merge one or more arrays | |
// $array1 = array("color" => "red", 2, 4); | |
// $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4); | |
// $result = array_merge($array1, $array2); | |
// Array | |
// ( | |
// [color] => green | |
// [0] => 2 | |
// [1] => 4 | |
// [2] => a | |
// [3] => b | |
// [shape] => trapezoid | |
// [4] => 4 | |
// ) | |
} | |
$drive_string = implode(',', $directories); // adding comma separated in array using implode() function | |
return $drive_string; | |
} else { | |
return "/usr/bin/mysqldump,/bin/mysqldump,/usr/local/bin/mysqldump,/usr/sfw/bin/mysqldump,/usr/xdg4/bin/mysqldump,/opt/bin/mysqldump"; | |
} | |
} | |
echo "mysqldump path : " . mysqldump_list() . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment