Create function for MySQL queries