首页 > 数据库技术 > 详细

python查询mysql中是否存在某张表(传参)

时间:2019-12-10 17:39:03      阅读:276      评论:0      收藏:0      [点我收藏+]

客户端输入了表的名字,服务端判断表是否存在。

参考:https://blog.csdn.net/qq_36523839/article/details/80639297

需要导入re模块: import re 

def confirm():
    tablename=request.form[tablename]#tablename是传过来的表名
    print(tablename:+tablename)
    sql = "show tables;"
    cursor.execute(sql)#执行sql语句
    tables = [cursor.fetchall()]#返回所有结果
    table_list = re.findall((\‘.*?\‘),str(tables))
    table_list = [re.sub("",‘‘,each) for each in table_list]
    print(table_list)
    if tablename in table_list:#存在
        return 1
    else:#不存在
        return 0

其中re的两次操作

技术分享图片

 

 

的作用:

 

python查询mysql中是否存在某张表(传参)

原文:https://www.cnblogs.com/glam/p/12017878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!