modified https://github.com/colshrapnel/safemysql/blob/master/safemysql.class.php