Rewrote, using myslqli instead of mysql