繁体   English   中英

如果查询不在MySQL数据库中,则会显示错误消息

[英]Display error message if inquiry not in mySQL databases

我在cgi文本文件中有以下代码:

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数据库返回空集。

不只是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM