title: How to use multiple variables in pymysql
body: <h1>How can I use multiple variables in my query:</h1>
  <pre><code>import pymysql
  
  def get_firstname(y):
  
  
  db = pymysql.connect(host=&quot;xxx.xxx.xxx.xxx&quot;, 
      user=&quot;xxxx&quot;,  
      passwd=&quot;xxxxx&quot;,     
      db=&quot;XXXXXXX&quot;)   
  
  cur = db.cursor()
  
  query = &quot;SELECT first_name FROM information WHERE x = y;&quot; 
  cur.execute(query, (y))
  
  result = str(cur.fetchone()[0])
  return(result)
  
  x = user_id
  y = 1
  
  
  print (get_firstname(y))
  </code></pre>
  <p>I would like to be able to change x to different variables, depending on my choice. Like user_id, last name, email etc. All columns in my database. #y is another variable which represent the value of the column in my database.</p>
  <p>Ex1: if x is &quot;user_id&quot; and y is &quot;1&quot;, then the result is the first name of the person with user_id 1.</p>
  <p>Ex2: if x is &quot;email&quot; and y is &quot;person@person.com&quot;, then the result is the first name of the person with the email person@person.com.</p>