Python Forum
Mysql returning number of rows not data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mysql returning number of rows not data
#1
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
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply
#4
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Thank you, me being very stupid today...
Not including...
cursor.fetchall()
Wall Wall Wall
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 2 110 Yesterday, 10:11 AM
Last Post: Pedroski55
  Create X Number of Variables and Assign Data RockBlok 8 922 Nov-14-2023, 08:46 AM
Last Post: perfringo
  Returning Column and Row Data From Spreadsheet knight2000 0 432 Oct-22-2023, 07:07 AM
Last Post: knight2000
  Mysql and mysql.connector error lostintime 2 660 Oct-03-2023, 10:25 PM
Last Post: lostintime
  how do you style data frame that has empty rows. gsaray101 0 522 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  Sequential number for rows retrieved and storing the Primary UKey to the line number GYKR 2 571 Aug-22-2023, 10:14 AM
Last Post: GYKR
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,212 Dec-19-2022, 11:11 PM
Last Post: Stockers
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,867 Dec-12-2022, 08:22 PM
Last Post: jh67
  Basic SQL query using Py: Inserting or querying sqlite3 database not returning data marlonbown 3 1,354 Nov-08-2022, 07:16 PM
Last Post: marlonbown
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,957 Feb-09-2022, 09:55 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020