python中mySQL的最后一个值(查询)

2024-04-19 01:02:30 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试从MySQL的Raspberry Pi上获取最后一个值。不知道为什么我的简单代码不能工作,在行=游标.fetchone().

这是我的代码:

# External module imports
import time
import os
import datetime
import MySQLdb

# Connect to mysql
db=MySQLdb.connect("localhost","zikmir","gforce","temp_database")
# Prepair a cursor    
cursor=db.cursor()

# Select three columns, id, time and temp from table time_temp
cursor.execute = ("SELECT id, time, temp FROM time_temp")
# ID is autoincremented value, time is in TIME and temp is float 

row = cursor.fetchone()
# Trying to store the last result in variable row

# Close cursor and database
cursor.close()
db.close()

Tags: andto代码inimportiddbtime