Tag Archives formysql

Change mysql_ to mysqli_ functions

In the process of upgrading PHP5.3 code I had to change all deprecated mysql_* functions to their mysqli_* counterparts.

For a lot of functions the signature stayed the same.

But mysqli_query and mysqli_connect have differences. So you can’t just find and replace them.

Instead of doing this manually, I wanted to find and replace recursively while changing the order of the arguments.

In vim:


Using sed:


Recursively changing all files:


Note that sed cannot do non greedy matching.

That’s why we’re searching for anything but the separator until the separator like this:


It basically states: get everything except for the comma until you get a comma (which is the first one to appear).

>