擅长:python、mysql、java
<p>发生错误是因为您传递给insert的其中一个值包含单引号。MySQL无法区分嵌入引号和周围引号的消歧。在</p>
<pre><code>'Kristopher O'Connell'
</code></pre>
<p>下面是一种使用绑定参数的替代语法,它应该适用于python:</p>
^{pr2}$
<p>使用这种语法,您的数据库驱动程序可以在后台自动处理转义。这也是一种更安全的语法,可以防止SQL注入。在</p>
<p>注意:根据您使用的API,也可能是:</p>
<pre><code>cursor.execute(
"INSERT INTO LSU.Student
(Semail, Spassword, Sname, Sage, Sgender, Smajor, Sstreet, Szipcode)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(a, b, c, d, e, f, g, h)
)
</code></pre>