MySQLi support for database module

In php 5.5 old mysql extension is mareked as deprecated and k3.3 throwing E_DEPRECATED here.

I've copy/paste and refactor for mysqli support.