faqts : Computers : Programming : Languages : Python : Snippets : Databases

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 5 people (80%) answered Yes
Recently 2 of 3 people (67%) answered Yes

Entry

User class for connecting to MySQL database

Jul 5th, 2000 10:01
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 207, Boudewijn Rempt


"""
Packages: database
"""
#! /usr/local/bin/python
#
# db.py - localized database access for Dramatis Personae
#
import MySQL
class Connection:
  def __init__(self, hostname, username, databasename):
    self.dbConnection = MySQL.connect(hostname,username, '')
    self.dbConnection.selectdb(databasename)
  def do (self, strSQL):
    return self.dbConnection.do(strSQL)
  def qry (self, strSQL):
    return self.dbConnection.do(strSQL)
  def disconnect (self):
    self.dbConnection.close
  def ins (self, strSQL):
    self.dbConnection.do(strSQL)
  def upd (self, strSQL):
    self.dbConnection.do(strSQL)
  def escape(self, str):
    return MySQL.escape(str)