Python

Python Scripts

Python MySQL Tutorial

MySQLdb vs _mysql

#!/usr/bin/env python

"""
Simple example to show how the _mysql module works
""" 
import _mysql
import sys

# try to establish a connection and show tables.
try:
connection = _mysql.connect('hostname', 'user', 'password', 'dbname')
connection.query("show databases")

print("Databases:")
databases = connection.use_result()
for db in databases:
print(db)

except _mysql.Error, error:
print("Error %d: %s", % (error.args[0], error.args[1])
sys.exit(1)
 
(Comments)

Comments