Replaced mysql function calls with mysqli