第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python中使用mysql.connector連接mysql時,幾乎一樣的語句insert可以,但是select就報錯,求助

python中使用mysql.connector連接mysql時,幾乎一樣的語句insert可以,但是select就報錯,求助

慕田峪7331174 2019-02-24 21:56:33
mysql的數(shù)據(jù)表是這樣的: +----+------+------+ | id | name | age | +----+------+------+ | 1 | cxx | 25 | +----+------+------+ 我的python代碼: cursor = conn.cursor() add_user = """insert into person(name,age) VALUES (%s,%s)""" data_user = (newName,newAge) cursor.execute(add_user,data_user) conn.commit() cursor.close() cursor = conn.cursor() select_user = """select * from person where name = (%s)""" select_data = (newName) cursor.execute(select_user,select_data) conn.commit() values = cursor.fetchall() values 上半部分的插入語句是可以正常執(zhí)行的,但是下半部分的搜索語句總是報錯, ProgrammingError: 1064 (42000): 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 '%s)' at line 1 應(yīng)該是字符串處理問題。。select_data沒有替換掉select_user中的%s,但是上面的為什么就可以。。求高手解答
查看完整描述

2 回答

?
繁花不似錦

TA貢獻(xiàn)1851條經(jīng)驗 獲得超4個贊

最終解決方案:
select_user = r'select * from person where name = %s'
select_data = (newName, )

查看完整回答
反對 回復(fù) 2019-03-01
?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊

"""select * from person where name = (%s)""" 

估計是這里錯了,為何要加括號呢?換成下面的試試

"""select * from person where name = %s """ 
查看完整回答
反對 回復(fù) 2019-03-01
  • 2 回答
  • 0 關(guān)注
  • 676 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號