Replace several mysql functions with mysqli