美文网首页
python 获取mysql 表的所有字段

python 获取mysql 表的所有字段

作者: yangsir001 | 来源:发表于2020-06-26 13:22 被阅读0次

def getcolumns(tbname):

#dgkj 为数据库名称

    sql = "select COLUMN_NAME from information_schema.COLUMNS where TABLE_SCHEMA='dgkj' and table_name = '{}'".format(tbname)

    conn = getconn()

    cur = conn.cursor()

    cur.execute(sql)

    lsfld = [tfld[0] for tfld in cur.fetchall()]

    cur.close()

    conn.close()

    return lsfld

相关文章

网友评论

      本文标题:python 获取mysql 表的所有字段

      本文链接:https://www.haomeiwen.com/subject/ufgmfktx.html