擅长:python、mysql、java
<p>您需要将一个序列(一个<code>list</code>或<code>tuple</code>)传递给<code>params</code>in<code>cursor.execute</code>语句:</p>
<pre><code>db_insert = "INSERT INTO TEXT(text) VALUES (%s)"
# notice the comma at the end to convert it to tuple
cursor.execute(db_insert,(enc,))
</code></pre>
<p>您可以在<a href="http://mysql-python.sourceforge.net/MySQLdb.html#some-examples" rel="nofollow">documentation</a>中阅读更多:</p>
<blockquote>
<p>Why the <code>tuple</code>? Because the DB API requires you to pass in any parameters as a sequence.</p>
</blockquote>
<hr/>
<p>或者,您甚至可以使用<a href="https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html" rel="nofollow">named parameters</a>:</p>
^{pr2}$