My search in MySQL it's not working (Python)
<p>I'm trying to get information from a database I have. But everytime I search it says there is nothing that follows the query. This is what I have.</p>

<pre><code>import datetime
import MySQLdb

db = MySQLdb.connect(user='root', passwd='', host='localhost', db = 'data') or die ('Error while connecting')
cursor = db.cursor()
sqlread = "SELECT * FROM humidity WHERE Date_Hour BETWEEN %s AND %s"

ts1 = ('%s/%s/%s 07:00:00') % (now.year, now.month, now.day)
ts2 = ('%s/%s/%s 03:00:00') % (now.year, now.month, now.day+1)

tsdata = (ts1,ts2)
cursor.excecute(sqlread,tsdata)
db.commit()
result = cursor.fetchall()
print result
</code></pre>

<p>Therefore, the results is 0. But I made the same search on phpMyAdmin and it worked. What I'm doing wrong?</p>

<p><strong>UPDATE:</strong></p>

<p>Here is my result as Jason commented. <a href="http://i.stack.imgur.com/vx5P2.png" rel="nofollow"><img src="http://i.stack.imgur.com/vx5P2.png" alt="enter image description here"></a>
However, I think Jason is right. I'm doing a GUI that make some charts. And I have 2 windows. One is making a graph with an animation using matplotlib, the program make the graphics with new data that is recolected from the database, so it is always asking. The other window just make one query but it doesn't work, so it could be possible because I'm asking "twice"?.</p>

<p>Your <code>db.commit()</code> might be throwing it off. However, lots of factors could play a part in this. You might also consider printing out your SQL query to see what is being put so like this:</p>

<p>Try setting up your code like this, it should lead you in the right direction:</p>

<pre><code>import MySQLdb as mdb
conn = mdb.connect('localhost', 'user', 'password', 'database_name')
try:
    cur = conn.cursor()
    ts1 = ('%s/%s/%s 07:00:00') % (now.year, now.month, now.day)
    ts2 = ('%s/%s/%s 03:00:00') % (now.year, now.month, now.day + 1)
    sqlread = "SELECT * FROM my_table where blah between {} and {}".format(ts1, ts2)
    print(sqlread)
    cur.execute(sqlread)
    res = cur.fetchall()
except mdb.Error as e:
    pass
finally:
    if conn:
        conn.close()
</code></pre>

python mysql datetime