search

Home  >  Q&A  >  body text

python3.x - When using pymysql to insert data in python, an error occurs when the data is an alphabetic string.

Use pymysql to insert data in python3, the code is as follows

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()

The result is the following error:

pymysql.err.InternalError: (1054, "Unknown column 'lison' in 'field list'")

If you change "lison" to "123", a numeric string can be inserted. Please tell me the reason. Also, when the numeric string is "0000", the result saved in the database will become 0. How to stop him from converting it into numbers?

滿天的星座滿天的星座2717 days ago1062

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-06-12 09:27:33

    insertSql = "INSERT INTO user(user_phone,user_name,user_password) VALUES(%s,'%s',%s)" % ('17855555555','lison','0000000')

    reply
    0
  • Cancelreply