
book 表 id,name,price con = pymysq.connect() db = con.cursor() data = db.execute("select name,price from origin_book").fetchall() ''' data= [('x1',100),('x2',200)] ''' db.execute("insert into book(name,price) values(%s,%s)",data) 1 chendl111 Aug 23, 2022 via Android 这是语法问题吧? |
2 kkeep Aug 23, 2022 via Android 你 fetchall 出来的('x1',100) 可能并不是 tuple 是 RowProxy 之类的吧 ,只是打印出来是这个样子, |
3 abersheeran Aug 23, 2022 你 fetch 出来的是类 Mapping 的 Row 对象…… |
4 xooass Aug 24, 2022 cOnn= pymysql.connect( host="127.0.0.1", user="",password="", database="", charset="", cursorclass=pymysql.cursors.DictCursor ) cursor = conn.cursor() cursor.execute("SQL") data = cursor.fetchall() ref = data['orders'] 不用 tuple ,用 dict 精准命中 |