Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- class Database:
- host = 'localhost'
- user = 'root'
- password = ''
- db = 'watcherservice'
- def __init__(self):
- self.connection = MySQLdb.connect(self.host, self.user, self.password, self.db)
- self.cursor = self.connection.cursor()
- def insert(self, query):
- try:
- self.cursor.execute(query)
- self.connection.commit()
- except:
- self.connection.rollback()
- def query(self, query):
- cursor = self.connection.cursor( MySQLdb.cursors.DictCursor )
- cursor.execute(query)
- return cursor.fetchall()
- def __del__(self):
- self.connection.close()
- if __name__ == "__main__":
- db = Database()
- CREATE TABLE IF NOT EXISTS `detalles` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `fecha` date NOT NULL,
- `hora` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `archivos_movidos` int(11) NOT NULL,
- `estado` text NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Add Comment
Please, Sign In to add comment