Guys, I'm stumped here. Trying to retrieve a row from mysql using MySQLdb, I receive the number of matching rows found, not the data itself.

here's the code:

def getKbd(kb_num):
    query="SELECT kbd_name, kbd_data, kbd_ps FROM kbd_ WHERE kbd_number = %d " % kb_num
    a = c.execute(query)
    return a

print getKb(3)

the output is 1 (since one row matches. if I do sELECT * I get the number of rows in db.

here's the same query in mysql:

mysql> SELECT kbd_name, kbd_data, kbd_ps FROM kbd_ WHERE kbd_number = 3 ;
+-------------------------------------+------------------------------------------------------------------+-----------+
| kbd_name | kbd_data | kbd_passes |
+-------------------------------------+------------------------------------------------------------------+-----------+
| kbd name number 3 | kbd data for number 3 in here | 0 |
+-------------------------------------+------------------------------------------------------------------+-----------+
1 row in set (0.00 sec)


What I want to receive as output is a list or tuple with something like

After

a = c.execute(query)
print c.fetchall()

should give u the output...

Thanks, I've just come up with the same. Strange how the cursor does everything standart sql syntax does, but doesn't return queries

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.