[Tutor] numrows returning -1

Paul Steele paul.steele1 at gmail.com
Fri Nov 22 23:08:25 CET 2013


Hey all...

I am getting a numrows count of -1 when I print numrows (see line 23 of the
code).   What does "-1" mean?    I think my connection is working and my
table has data.

Here's my code...

#!/usr/bin/python
# -*- coding: utf-8 -*-

import mysql.connector
from mysql.connector import errorcode

try:
  con = mysql.connector.connect(user='root', password='pw848596',
                              host='127.0.0.1',
                              database='mydb')
except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exists")
  else:
    print(err)
else:
  cur=con.cursor()

  cur.execute("select Name from Rosters")
  numrows = cur.rowcount
  print numrows
  for x in xrange(0,numrows):
      row = cursor.fetchone()
      print "Name"

con.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131122/bf7c39de/attachment-0001.html>


More information about the Tutor mailing list