0

Trying to get the last value from MySQL on Raspberry Pi. No idea why my simple code wont work, gives error at "execute() first" at row = cursor.fetchone().

Here is my code:

# 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()
2
  • Looks correct: It will fail however if there is no data in the table time_temp Commented Apr 30, 2017 at 3:41
  • @NorbertvanNobelen I do have data in the table, I'm pushing data and also fetching it successfully at my website in php. www.ziks.ca Commented Apr 30, 2017 at 4:10

1 Answer 1

1

watch the = incursor.execute = ("SELECT id, time, temp FROM time_temp"). It should read cursor.execute("SELECT...")

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.