Created
January 8, 2014 07:04
-
-
Save stefanmonkey/8312907 to your computer and use it in GitHub Desktop.
MySQLdb module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import MySQLdb as mdb | |
import sys | |
try: | |
con = mdb.connect('localhost', 'testuser', '123456', 'testdb') | |
cur = con.cursor() | |
cur.execute('select version()') | |
ver = cur.fetchone() | |
print "Database version : %s " % ver | |
except mdb.Error, e: | |
print "Error %d: %s" % (e.args[0], e.args[1]) | |
sys.exit(1) | |
finally: | |
if con: | |
con.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment