Changed in-buit CI database function to full mysql queries