2010-03-10 71 views

回答

7

只需选择一行。如果你没有收到任何东西,它是空的! (从MySQLdb的部位实施例)

import MySQLdb 
db = MySQLdb.connect(passwd="moonpie", db="thangs") 
results = db.query("""SELECT * from mytable limit 1""") 
if not results: 
    print "This table is empty!" 
3

喜欢的东西

import MySQLdb 
db = MySQLdb.connect("host", "user", "password", "dbname") 
cursor = db.cursor() 
sql = """SELECT count(*) as tot FROM simpletable""" 
cursor.execute(sql) 
data = cursor.fetchone() 
db.close() 
print data 

将打印在simpletable表中的号码或记录。
然后,您可以测试是否大于零。