Skip to content

Instantly share code, notes, and snippets.

@DNTech
Created April 5, 2021 16:38
Show Gist options
  • Save DNTech/7b9448c2dffa66b444f3a81897ee2e68 to your computer and use it in GitHub Desktop.
Save DNTech/7b9448c2dffa66b444f3a81897ee2e68 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)){
echo "working on $fl\n";
$content = file_get_contents($fl);
$content = str_replace('mysqli_query($conn, $query)', 'mysqli_query($conn, $query)', $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