37,719
社区成员
发帖
与我相关
我的任务
分享
sql_s='select count(*) from illegalityMacUser where lm_time>=%s and mac=%s '
datetime=time.strftime('%Y-%m-%d',time.localtime(time.time()))
print datetime
cur.execute(sql_s,datetime,'dd-dd-dd-dd-f8')
for row in cur.fetchall():
for r in row:
print 'begin out 今天所有的数据=============',r
if(r==0):
print 0
else:
print 1
如果时间或者mac只写一个比如
sql_s='select count(*) from illegalityMacUser where mac=%s'
cur.execute(sql_s,'dd-dd-dd-dd-f8')
没问题
或者
sql_s='select count(*) from illegalityMacUser lm_time>=%s'
cur.execute(sql_s,datetime)
也没问题
可是2个条件都加就报错?怎么回事呢 错误如下
raceback (most recent call last):
File "D:\Python-1 - 副本.py", line 19, in <module>
cur.execute(sql_s,datetime,'dd-dd-dd-dd-f8')
TypeError: execute() takes at most 3 arguments (4 given)
#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
# Prepare SQL query to INSERT a record into the database.
sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \
LAST_NAME, AGE, SEX, INCOME) \
VALUES ('%s', '%s', '%d', '%c', '%d' )" % \
('Mac', 'Mohan', 20, 'M', 2000)
try:
# Execute the SQL command
cursor.execute(sql)
# Commit your changes in the database
db.commit()
except:
# Rollback in case there is any error
db.rollback()
# disconnect from server
db.close()
datetime=time.strftime('%Y-%m-%d',time.localtime(time.time()))
mac = 'dd-dd-dd-dd-f8'
sql_s=" 'select count(*) from illegalityMacUser where lm_time>=%s and mac=%s' % (datetime, mac)"
print datetime
cur.execute(sql_s)
mac号是12位十六进制数的吧
sql_s='select count(*) from illegalityMacUser where mac=%s and ...'
cur.execute(sql_s,'dd-dd-dd-dd-f8')
?不可以