查看数据库里有没有数据

 

#!/usr/bin/env python
# coding:utf8
# author:Z time:2018/8/28
import pymysql

connect=pymysql.Connect(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='',
    db='haha',
    charset='utf8'

)
cursor=connect.cursor()
sql="""
select count(*) from hehe
"""
cursor.execute(sql)
a=cursor.fetchall()#((0,),)

if a[0][0]==0:#判断数据库是否为空
    print('没有数据')

计算数据库中数据的数量

 

 

 

((0,),)

输出为0,表示没有数据

 

 

终端输出的结果

 

posted @ 2018-08-28 09:56  Operater  阅读(524)  评论(0编辑  收藏  举报