-
-
Save guryashzone/f5630fcf419d932cf8de8edcfa584e8e to your computer and use it in GitHub Desktop.
Replace mysql to mysqli within a directory hierarchy
This file contains 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 | |
$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