Python + request connection using pymysql mysql database operation, Basics "eleven"

Note-taking:

(1) pymysql all about updating data (insert, update, delete) operations need to commit, or can not submit data to the database, as with commit (), there must be a corresponding rollback (), commit () It represents submission, rollback () represents rollback

When there is Chinese characters (2) sql statement, need time in pymysql.connect (), specifying add the parameter charset = 'utf8', otherwise the Chinese garbled. Get query data: cursor.fetchone () Gets the remainder result of the first data row, cursor.fetchmany (3) obtain the remaining results of the first three rows of data, cursor.fetchall () All the remaining acquired data results.

(3) cursor to provide a parameter can get the latest insert auto-incremented id, which is the last inserted a data ID, if not insert too, will perform cursor.lastrowid error

 

#方式1:pymysql.connection()中指定参数
conn = pymysql.connect(
    host = "127.0.0.1",
    user = "root",
    password = "",
    database = "hetingdemo",
    charset = 'utf8',
    cursorclass = pymysql.cursors.DictCursor)

 

Guess you like

Origin www.cnblogs.com/syw20170419/p/11006821.html