import mysql.connector as conn
mydb = conn.connect(
host="localhost",
user="root",
passwd="password",
database="python_mysql"
)
mycursor = mydb.cursor()
计算数据库“ python_mysql”中的表数
mycursor.execute("SELECT FOUND_ROWS();") #This contains 3 as result
如何通过使用新变量将结果打印为3
答案 0 :(得分:1)
通过获取和分配,我们可以获得计数
mycursor.execute("SELECT FOUND_ROWS();")
data = mycursor.fetchall()
print(data[0][0]) # prints 3
答案 1 :(得分:0)
import mysql.connector as conn
mydb = conn.connect(
host="localhost",
user="root",
passwd="password",
database="python_mysql"
)
mycursor = mydb.cursor()
mycursor.execute("select count(*) from information_schema.tables where table_schema = database();")
data = mycursor.fetchall()
print(data[0][0])