Python send to db-problems

Viewed 23

I want the variable 'x2' to be sent to the db every time it changes, but can't figure it out or find any tutorial on how to do it. What do I do wrong and how can I fix it? I have tried this:

        x2 = x + int(w/2)
        y2 = y + int(h/2)
        cv2.circle(frame,(x2,y2),4,(0,255,0),-1) #siktet
        print(x2)

 
        text = "x: " + str(x2) + ", y: " + str(y2)
        cv2.putText(frame, text, (x2 - 10, y2 - 10),
            cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
         
        cv2.imshow('frame',frame)
 
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    conn = MySQLdb.connect(host= "localhost",
                  user="root",
                  passwd="",
                  db="fish_db")
x = conn.cursor()

try:
   x.execute("""INSERT INTO position VALUES (%s)""",(x2))
   conn.commit()
except:
   conn.rollback()

conn.close()

    cap.release()
    cv2.destroyAllWindows()

 
if __name__ == '__main__':
    print(__doc__)
    main()
0 Answers
Related