2014-05-12 37 views
0

我有這樣的代碼在CGI文本文件:顯示錯誤消息,如果查詢不能在MySQL中的數據庫

if inquiry == "Number": 
    cursor.execute('SELECT * from NUMBER_INFO where NUMBER_ID = "%s";' %(inquiry)) 
    number_info = cursor.fetchall() 
    number = number_info[0][1] 

在本質上是用戶輸入的值,它會搜索我的MySQL數據庫和輸出值。

我想知道如何在數據庫中找不到用戶輸入的內容,如何輸出錯誤信息,例如數值不在數據庫中?

我所知道的是,mysql數據庫返回空集。

回答

0

是不是隻是

if not number_info: 
    print "nothing's there" 
else: 
    number = number_info[0][1] 

相關問題