python3中使用pymysql插入數據,程式碼如下
import pymysql
HOST = "localhost"
USER_NAME = "root"
PASSWORD = "712123000"
DB_NAME = "jiwenjuan"
def connDB():
conn = pymysql.connect(host=HOST,user=USER_NAME,passwd=PASSWORD,db=DB_NAME);
return conn
conn = connDB()
cursor = conn.cursor()
insertSql = "INSERT INTO user(user_phone,user_name,user_password) VALUES(%s,%s,%s)" % ('17855555555','lison','0000000')
cursor.execute(insertSql)
conn.commit()
結果報如下錯誤:
pymysql.err.InternalError: (1054, "Unknown column 'lison' in 'field list'")
如果吧"lison" 改為"123"這種數字字串就能插入,請教大神是什麼原因,還有就是當數字字串是"0000"的時候存到資料庫結果會變成0 ,怎麼讓他不要轉換成數字?
雷雷