0

I am quite familiar with the php but having troubles using sql in the python. In php, i used these lines to see if the query gives some result or not.

$query="SELECT ID FROM Employee WHERE user='$username' AND pass='$password'"; 

 $query_num_rows= mysql_num_rows($query_run); //returns number of rows

Is there such codes in the python? any resources would be appreciated too. i am having a hard time in using sql in python

2 Answers 2

2

The cursor has a rowcount property:

print(cursor.execute('SELECT ID FROM Employee').rowcount)
Sign up to request clarification or add additional context in comments.

2 Comments

So long as the cursor in question implements the DB API, anyway.
please check my answer below. i get some error :( @BoshWash
0
db= MySQLdb.connect("localhost","root","ahmed","practice")
    cursor=db.cursor()

    #checking phase to stop scrapping
    sql = "SELECT short_link FROM Properties WHERE Short_link='link_result'"
    print (cursor.execute(sql).rowcount)

i am using these lines and it gives error AttributeError: 'long' object has no attribute 'rowcount'

Then I used this which always give 0 result (shouldnt give zero since in the database, it should be matched)

sql = "SELECT Short_link FROM Properties WHERE Short_link='link_result'"
    print cursor.execute(sql)
    print cursor.rowcount

2 Comments

does it still return 0 if you "SELECT * FROM Properties"?
also, if you have more questions don't post them as answers, just edit your original question or write a comment

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.