0

Why this code returns nothing?

ip = '10.113.205.55'

cursor.execute("Select * from tablename WHERE ip like '%s' "), ip

result = cursor.fetchall()

print result

when i use the code below it works:

cursor.execute("Select * from tablename where ip like '10.113.205.55' ")

result = cursor.fetchall()

print result
1

2 Answers 2

1

You should remove the ' and put ip inside the parameter list:

cursor.execute("SELECT * FROM tablename WHERE ip LIKE %s", [ip])
Sign up to request clarification or add additional context in comments.

Comments

0

change the argument of cursor.execute method to:cursor.execute("Select * from tablename WHERE ip like '%s'" % ip)

2 Comments

OMG, how i didnt see that... It Works now, thnx!
But look at @Daniel answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.