Skip to main content

Posts

Showing posts from August, 2020

Using a vim macro to fix 'mysql_' calls with regex

 I'm working on a largish project, converting it to work from early PHP 5 to PHP 7.3 and I found myself spending a lot of time converting all those various mysql_* to their equivalent procedural mysqli_* function calls. Mostly pretty tedious. Anytime you encounter something tedious that you'll have to do on a ton of files, it's a chance for automation. In this case, I decided come up with a vim macro that would automagically convert the most commonly occurring function calls. Here's the macro, which uses 4 regular expressions to search and replace the four most common ones - then followed by a search for "mysql_" to catch any outliers. :% s/mysql_query(\(.\{-}\),\(.\{-}\))/mysqli_query(\1 , \2)/eg :% s/mysql_fetch/mysqli_fetch/eg :% s/mysql_num/mysqli_num/eg :% s/mysql_close/mysqli_close/ge :/mysql_ The easiest way to use this is to paste into a new document, then select it all and yank it into a buffer. Then just run the buffer as macro. So, I used 'm...