Advertisement
Guest User

SQL Fetch

a guest
Apr 5th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. def getplayer1name(candidatenumber):
  2.     # search the database for the forename related to the candidate number
  3.     # inputted by player 1, use this name to address them in the game.
  4.     cnx = mysql.connector.connect(host='localhost', user='ballt',
  5.                                   password='password',database='pythondb')
  6.     cursor = cnx.cursor()
  7.     cursor.execute("""SELECT Forename FROM pythondb.student """
  8.                    """WHERE CandidateNumber = %s""" % (candidatenumber))
  9.    
  10.     for row in cursor.fetchall():
  11.         output = row[0]
  12.     return output
  13.    
  14.     cnx.close() # close the connection to the database to reduce processing overheads
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement