MySQL Forums
Forum List  »  Connector/Python

Check if a record exists
Posted by: Dani Valverde
Date: July 22, 2010 06:09AM

Hello!
I am writing a python function to check if a user exists in a database. This is the code:

def searchUser():
print 'Which user are you looking for?'
Username = raw_input('> ')
sql = '''IF EXISTS (SELECT * FROM Users WHERE Username = %s)
PRINT 'User exist'
ELSE
PRINT 'User does not exist'''
cursor.execute(sql, (Username))
result = cursor.fetchall()
However, when I run it it returns a syntax error. Can anyone help me to write it properly?
Cheers!

Dani

Options: ReplyQuote


Subject
Written By
Posted
Check if a record exists
July 22, 2010 06:09AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.