コード例 #1
0
ファイル: db.py プロジェクト: tonym415/ISaidItBest_prod
class db(object):
    """docstring for db"""

    _config = conn.connStr()
    _cnx = None
    _cur = None

    def __init__(self):
        try:
            self._cnx = mysql.connector.connect(**self._config)
            self._cur = self._cnx.cursor()
        except mysql.connector.Error as err:
            if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
                print("Something is wrong with your user name or password")
            elif err.errno == errorcode.ER_BAD_DB_ERROR:
                print("Database does not exist")
            else:
                print(err)
            self._cnx.close()

    def query(self, query, params=None):
        return self._cur.execute(query, params)

    def __del__(self):
        self._cnx.close()
コード例 #2
0
ファイル: db2.py プロジェクト: tonym415/ISaidItBest_prod
def get_connection():
    """ returns a connection to the database """
    global _connection
    global _connector

    _connector = mysql.connector
    try:
        if not _connection:
            _connection = _connector.connect(**conn.connStr())
    except mysql.connector.Error as err:
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
            print("Something is wrong with your user name or password")
        elif err.errno == errorcode.ER_BAD_DB_ERROR:
            print("Database does not exist")
        else:
            print(err)

    return _connection
コード例 #3
0
ファイル: recipe.py プロジェクト: tonym415/DRDB
#!/usr/bin/python
This script provides all back-end functionality to the Digital Recipe Library
"""
import os
import cgi
import cgitb
import json
import mysql.connector
from mysql.connector import errorcode
import sys

sys.path.append('./')
import conn

cgitb.enable()
config = conn.connStr()


def cgiFieldStorageToDict(fieldStorage):
    # get a plain dictionary, rather that the '.value' system used by the
    # cgi module
    params = {}
    for key in fieldStorage.keys():
        params[key] = fieldStorage[key].value
    return params


def createItem(info):
    # create items into the database
    # dbg statement
    #sys.stderr.write("info: %s" % info['entity'])