python/ mysql

My Code

Second last line is showing error <Unread.result.found> but when i run it individually it run successfully

import mysql.connector as msqc
import numpy as np

db = msqc.connect(
    host="localhost",
    username="root",
    password=" ",
    database="hotel",
)
cur = db.cursor()

ss = 'SELECT one_bed ,Available_one_bed from rooms where Available_one_bed = "A" '
cur.execute(ss)
available_room = cur.fetchone()
print(available_room[0])
cur.execute('SELECT * from rooms')
s = 'UPDATE rooms SET Available_one_bed = "N/A" WHERE one_bed = '+str(100)
cur.execute(s)

Most likely not all data where read after first execute. You need a buffered cursor, eg

cur = db.cursor(buffered=True)

some details could be found here https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursorbuffered.html

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Integrating more than one function error in python how to give two or more than two values to a CSV cell in python How to call more than one function in python Python MySQL many function show InternalError: Unread result found xpath returns more than one result, how to handle in python How to display more than one result with Wolfram Alpha API (python) MySQL Unread Result with Python Run more than one server using python Python MySQL query more than one join How to write and run more than one code in Python IDLE?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM