所以我有一個問題非常類似this question,但有點不同。使用Python和mySQL(和Windows作爲操作系統),cursor.execute()返回沒有結果,但它連接
我打電話給cursor.execute(sqlString)
在一塊sql上工作正常,當我直接在mysql工作臺上運行它。當我運行代碼但是我沒有得到結果集。
我有完全相同的問題症狀,如鏈接中所述,我試過鏈接解決方案,但事實證明,我沒有同樣的問題。
返回時my _stored_results []爲空。
我使用try/except塊中的代碼,我有另一個python程序,它使用相同的代碼將csv加載到我的mySQL數據庫中,並且它可以工作。
我遇到問題的代碼是在@ app.route中,如果有任何不同之處。
我的代碼如下所示:
def functionName() :
try:
import mysql.connector
from mysql.connector import errorcode
cnx = mysql.connector.connect(user=init["dbDetails"][0], password=init["dbDetails"][1], host=init["dbDetails"][2], database=init["dbDetails"][3])
cur = cnx.cursor()
cur.close() #I deffo don't need the two lines below but they were added for a sanity check, just to make sure the cur was not being read from any other code.
cur = cnx.cursor() # and this one obviously
sqlString = 'CALL `schemaName`.`getProcedureName_sp`(1, 1, 0)'
cur.execute(sqlString, multi=True) # tried it here without the multi=True and got the msg telling me to use it.
getSomeDetails = cur.fetchall()
cnx.commit() # probably don't need to commit here I am just reading from the dB but I am trying anything as I have no idea what my issue might be.
return render_template('success.html')
except Exception as e:
return render_template('error.html', error = str(e))
finally:
cur.close()
cnx.close()
我很困惑,因爲我有相同的代碼在幾個地方工作。