python mysql插入語句 返回1064
問題描述
Traceback (most recent call last): File 'python_mysql.py', line 78, in <module>
x.cb_model_add()
File 'python_mysql.py', line 17, in cb_model_add
self.cursor.executemany(sql, params)
File 'build/bdist.linux-x86_64/egg/MySQLdb/cursors.py', line 262, in executemany File 'build/bdist.linux-x86_64/egg/MySQLdb/cursors.py', line 354, in _query File 'build/bdist.linux-x86_64/egg/MySQLdb/cursors.py', line 318, in _do_query_mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ’:code)’ at line 2')
sql語句如下:sql='insert into test1 (code) values (:code)'
params = [{’code’:’xx’}] self.cursor.executemany(sql, params)
問題解答
回答1:sql='insert into test1 (code) values (%s)'self.cursor.executemany(sql, code)
相關(guān)文章:
1. Python處理Dict生成json2. macOS Sierra 10.12 安裝mysql 5.7.1出現(xiàn)錯誤3. 網(wǎng)頁爬蟲 - python爬蟲用BeautifulSoup爬取<s>元素并寫入字典,但某些div下沒有這一元素,導(dǎo)致自動寫入下一條,如何解決?4. php - 生產(chǎn)環(huán)境下,給MySQL添加索引,修改表結(jié)構(gòu)操作,如何才能讓線上業(yè)務(wù)不受影響?5. mysql - 拖拽重排序后怎么插入數(shù)據(jù)庫?6. mysql 獲取時間函數(shù)unix_timestamp 問題?7. javascript - 微信小程序 wx.downloadFile下載文件大小有限制嗎8. 新入手layuiadmin,部署到tp中。想用php自已寫一個后臺管理系統(tǒng)。9. javascript - 天貓首頁首屏數(shù)據(jù)來源10. 網(wǎng)頁爬蟲 - python+smtp發(fā)送郵件附件問題
