title: MySQLdb Python insert %d and %s
body: <p>Precursor:</p>
  
  <pre><code>MySQL Table created via:
  CREATE TABLE table(Id INT PRIMARY KEY NOT NULL, Param1 VARCHAR(50))
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>.execute("INSERT INTO table VALUES(%d,%s)", (int(id), string)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>TypeError: %d format: a number is required, not a str
  </code></pre>
  
  <p>I'm not sure what's going on here or why I am not able to execute the command. This is using MySQLdb in Python. <code>.execute</code> is performed on a cursor object.</p>
  
  <p>EDIT: </p>
  
  <p>The question: <a href="https://stackoverflow.com/questions/5785154/python-mysqldb-issues">Python MySQLdb issues (TypeError: %d format: a number is required, not str)</a>
  says that you must use <code>%s</code> for all fields. Why might this be? Why does this command work?</p>
  
  <pre><code>.execute("INSERT INTO table VALUES(%s,%s)", (int(id), string)
  </code></pre>