Python2.4-检查是否有MySQL查询结果

Python2.4-检查是否有MySQL查询结果,python,mysql,python-2.4,Python,Mysql,Python 2.4,使用Python2.4,我想检查是否有任何结果(作为一行) 我用过: cmd_connection1 = ("mysql -uuser -ppw -h127.0.0.1 mydatabase -s" " -N -e \'select * from mytable where ID=\""+ID+"\";\'") 但是没有结果。我每天都在使用一个有效的例子 Im使用mysql连接器: 您可以从以下网站下载: 你应该使用Python3首先你不应该使用Pyt

使用Python2.4,我想检查是否有任何结果(作为一行)

我用过:

cmd_connection1 = ("mysql -uuser -ppw -h127.0.0.1  mydatabase -s"
                   " -N -e \'select * from mytable where ID=\""+ID+"\";\'")

但是没有结果。

我每天都在使用一个有效的例子

Im使用mysql连接器:

您可以从以下网站下载:


你应该使用Python3

首先你不应该使用Python2.4,因为它已经有14年的历史了,而且不受支持,其次你应该使用一个合适的python库来执行MySQL查询,而不是进行测试。为什么你要攻击我,我是python新手别紧张,谢谢你的回答,我会测试它。
        if not line1 :
            ...

        if line1 == "Empty" :
             ...
import mysql.connector
# impor mysql connector

cnx = mysql.connector.connect(user='your_user', password='your_pwd', host='you_host',database='your_database')
#create a conecction to mysql server
# change user, password, host and database according your needs

id_a_buscar =15
# i will search this value in my database

cursor = cnx.cursor()
# create a cursor

cursor.execute("""SELECT 

titulo,
clave


FROM

historico

WHERE

libro_pk =%s""", (id_a_buscar,))
# execute a query
# %s stores a variable
# id_a_buscar is assigned to s
# so the REAL query is SELECT titulo, clave FROM historico WHERE libro_pk = 15

resultados = cursor.fetchall()
# store query results in resultados

count = cursor.rowcount
# count how many rows return after the query

if count > 0:
    # if there are records
else:
    # if there are NO records