from pymysql import connect
check_data DEF (CUR):
sql = "from the SELECT * Student;" # sql statement cur.execute (sql) # sql statement to execute all records # obtain query the Result = cur.fetchall () Print (the Result) for value in the Result: print (value)
insert_data DEF (CUR, conn):
SQL = "" "INSERT INTO Student value (0," Little America "1990-01-02," female ");" ""
cur.execute (SQL)
conn.commit () to complete the # python enabled by default transactions, you must submit data modification
DEF main ():
# link database
conn = Connect (Host ="localhost",the User ="root",password ="MySQL",db ="python_1",= Port3306)
# get a cursor object using the cursor
CUR = conn.cursor ()
# query database information
check_data (CUR)
# insert data operation
insert_data (CUR, conn)
# close the cursor object
cur.close ()
# close links
conn.Close ()
IF __name__ == "__main__":
main ()
deletions, and modifications are not many, sql statement is just not the same as the corresponding. Here we do not repeat them!