Python Forum

Full Version: Mysql returning number of rows not data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Really odd thing today, when I query a mysql database I am getting the number of rows returned rather that the column data !

#!/usr/bin/python
# -*- coding:utf-8 -*-
import csv
import time
import MySQLdb 
try:
    db = MySQLdb.connect(host="localhost", user="root", passwd="",db="pension")
    cur = db.cursor()
except MySQLdb.Error, e:
    print "Error One %d: %s" % (e.args[0], e.args[1])
    
startdate = "2019-05-18"
enddate = "2019-05-19"
    
print cur.execute("SELECT * FROM pension.pension_payments WHERE date >= %s AND date <= %s",(startdate,enddate))
print cur.execute("SELECT * FROM pension.pension_payments")

Result would be:
4
4
but i have six columns in 4 rows

idpension_payments,date,week,name,employer,employee
69,"2019-05-18 16:47:35",10,Andrew,35.67,20.00
70,"2019-05-18 16:47:36",10,Alex,35.67,11.37
71,"2019-05-18 16:47:36",10,Sharon,35.67,7.05
72,"2019-05-18 16:47:36",10,Kerry,35.67,9.13
It looks like your sql statement has some COUNT in it. Check that your sql statement is indeed what you show in the code (e.g. if you had COUNT and then edit the file, make sure it is saved).
Also your print statement will yield list of tuples or something like this (e.g. dict depending on settings/options) and no column names. i.e. the output shown is not exact output from the code and possibly you have extra code.
I now know the root password on your computer. pension is the name of the file. Within this file are one or more tables. You look up a record in a table, not a file. Did you create this file? If so, post the code used to create the file and the table within it.
(Jun-10-2019, 01:56 PM)woooee Wrote: [ -> ]pension is the name of the file
it's mysql server. There is no local file (like sqlite3). pension is the schema and pension_payments

and root/williamemilylouis is user/password for the mysql server running on localhost, not the computer
Thank you, me being very stupid today...
Not including...
cursor.fetchall()
Wall Wall Wall