2014-05-12 41 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] 

相关问题