My database cannot query. when i run this code then it's show me an error .
def button_click(self):
# shost is a QString object
shost = self.le.text()
if shost:
s_h = "127.0.0.1"
s_n = "root"
s_p = ""
s_d = "code"
s_cn = mdb.connect(s_h, s_n, s_p, s_d)
cursor = s_cn.cursor()
today = datetime.date.today()
mac = get_mac()
query = "INSERT INTO `ac` (`acc`, `mac`, `date`) VALUES (%s, %s, %s)"
re = cursor.execute(query,(shost,mac,today,))
if re:
self.ex = Example()
self.ex.show()
else:
query1 = "SELECT * FROM `ac` WHERE `acc` = %s,`mac` = $s"
ck = cursor.execute(query1,(shost,mac))
if(ck):
self.ex = Example()
self.ex.show()
else:
print 'no'
I want to know how to write sql code with python variable so how can i fix it ?
query = "INSERT INTO `ac` (`acc`, `mac`, `date`) VALUES (%s, %s, %s)"
re = cursor.execute(query,(shost,mac,today,))
and
query1 = "SELECT * FROM `ac` WHERE `acc` = %s,`mac` = $s"
ck = cursor.execute(query1,(shost,mac))