Skip to content

Instantly share code, notes, and snippets.

@guryashzone
Forked from DNTech/script.php
Last active April 5, 2021 17:20
Show Gist options
  • Save guryashzone/f5630fcf419d932cf8de8edcfa584e8e to your computer and use it in GitHub Desktop.
Save guryashzone/f5630fcf419d932cf8de8edcfa584e8e to your computer and use it in GitHub Desktop.
Replace mysql to mysqli within a directory hierarchy
<?php
$folders = [
'*.php',
'*/*.php',
'*/*/*.php'
];
foreach ($folders as $f){
$res = shell_exec("ls $f");
$files = explode("\n", $res);
echo("\n");
foreach ($files as $fl){
if(is_file($fl) && pathinfo($fl, PATHINFO_EXTENSION) === "php"){
echo "working on $fl\n";
$content = file_get_contents($fl);
$old = ["mysql_query(", "mysql_fetch", "mysql_num", "mysql_error()"];
$new = ['mysqli_query($con, ', "mysqli_fetch", "mysqli_num", 'mysqli_error($con)'];
$content = str_replace($old, $new, $content);
file_put_contents($fl, $content);
echo "Corrected $fl\n\n";
}
}
}
echo 'done';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment