我試圖插入python變量到python腳本內的MySQL表,但它不工作。這裏是我的代碼MySQL連接器/ Python - 插入python變量到MySQL表
add_results=("INSERT INTO account_cancel_predictions"
"(account_id,21_day_probability,flagged)"
"Values(%(account_id)s,%(21_day_probability)s,%(flagged)s)")
data_result={
'account_id':result[1,0],
'21_day_probability':result[1,1],
'flagged':result[1,2]
}
cursor.execute(add_results,data_result)
cnx.commit()
cursor.close()
cnx.close()
此獲得誤差
ProgrammingError: Failed processing pyformat-parameters; 'MySQLConverter' object has no attribute '_float64_to_mysql'
然而,當我更換變量名result[1,0]
,result[1,1]
,並result[1,2]
用自己的實際數值,它的工作。我懷疑python是傳遞實際的變量名稱而不是它們所持有的值。我該如何解決?
任何人?........ – user1893354
connection = engine.connect() connection.execute(「」「更新玩家設置Gold =(?)其中Name =(?)」「」,(gold,名字)),也許只是一個fanboy的東西,但我傾向於使用python的sqlalchemy,這往往會簡化大部分這一點,我從來沒有使用通配符的問題 – theBigChalk