如何比较mysql数据库与输入? [英] how compare mysql database with input?
本文介绍了如何比较mysql数据库与输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello
我尝试将数据库mysql中的ID存储与使用Raspberry PI的python中读取RFID读取的ID进行比较。
如果正确的ID - > ON led
如何比较?
这是我的代码阅读器RFID:
import serial
import RPi.GPIO as GPIO
import MySQLdb
来自 binascii import hexlify
serial = serial.Serial( / dev / ttyAMA0,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 0 . 1 )
GPIO.setmode(GPIO.BOARD)
GPIO.setup( 12 ,GPIO.OUT)
send = \ xAA \ x00 \ x0 3 \\\ x25 \ x26 \ x00 \ x00 \ xBB
db = MySQLdb.connect(host = ' localhost',user = ' root',passwd = ' root',db = ' ex_1')
while 1 :
serial.write(send)
data = serial.readline()
tach = data [ 5 : 8 ]
hex = hexlify(tach)
num = int(hex, 16 )
print (num)# - >返回180031
如果(num == # 数据库mysql中的ID):
GPIO.output( 12 , True 跨度>);
else :
GPIO.output( 12 ,错误);
如何将num与数据库中的ID进行比较?
请帮助我。谢谢。
解决方案
好吧,我猜你是从数据库中获取ID开始的。
< a href =http://zetcode.com/db/mysqlpython/> MySQL Python教程 [ ^ ]
然后应该很容易比较这些值。 :)
Hello
I try to compare ID store in database mysql with ID read from reader RFID in python using Raspberry PI.
If right ID -> ON led
How can I compare it?
Here is my code reader RFID:
import serial
import RPi.GPIO as GPIO
import MySQLdb
from binascii import hexlify
serial = serial.Serial("/dev/ttyAMA0",
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 0.1)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
send = "\xAA\x00\x03\x25\x26\x00\x00\xBB"
db = MySQLdb.connect(host='localhost', user='root',passwd='root', db='ex_1')
while 1:
serial.write(send)
data = serial.readline()
tach = data[5:8]
hex = hexlify(tach)
num = int(hex,16)
print (num) #-> it return 180031
if (num == # ID in database mysql):
GPIO.output(12, True);
else:
GPIO.output(12, False);
how to compare "num" with ID in database?
Please help me. Thanks.
解决方案
Well, I guess you start with getting the ID from your database.
MySQL Python tutorial[^]
Then it should be easy to compare the values. :)
这篇关于如何比较mysql数据库与输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文