Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. hostname = '127.0.0.1'
  4. username = 'root'
  5. password = 'root'
  6. database = 'schooldb'
  7.  
  8. # Simple routine to run a query on a database and print the results:
  9. def doQuery( conn ) :
  10. cur = conn.cursor()
  11.  
  12. cur.execute( "SELECT fname, lname FROM students" )
  13.  
  14. for firstname, lastname in cur.fetchall() :
  15. print firstname, lastname
  16.  
  17.  
  18. print "Using MySQLdb…"
  19. import MySQLdb
  20. myConnection = MySQLdb.connect( host=hostname, user=username, passwd=password, db=database )
  21. doQuery( myConnection )
  22. myConnection.close()
  23.  
  24. print "Using pymysql…"
  25. import pymysql
  26. myConnection = pymysql.connect( host=hostname, user=username, passwd=password, db=database )
  27. doQuery( myConnection )
  28. myConnection.close()
  29.  
  30. print "Using mysql.connector…"
  31. import mysql.connector
  32. myConnection = mysql.connector.connect( host=hostname, user=username, passwd=password, db=database )
  33. doQuery( myConnection )
  34. myConnection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement