MySQL- Руководство разработчика



              

Использование модуля MySQL


import MySQL DBH = MySQL.connect() # localhost print DBH.listdbs() DBH.selectdb('test') print DBH.serverinfo() print DBH.stat() DBH["create table pytest (x int, y int, s char(20))"] DBH["insert into pytest values (1,2,'abc')"] DBH.do("insert into pytest values (3,4,'def')") STH = DBH.query("insert into pytest values (5,6,'ghi')") print STH.affectedrows() print DBH['select * from pytest'] STH = DBH.query("select * from pytest") print STH.numrows() print STH.fields() print STH.fetchrows(-1) STH.seek(0) print STH.fetchrows(1) print STH.fetchrows(1) STH.seek(0) print STH.fetchrows(2) print STH.fetchrows(2) print STH.numfields() STH.seek(0) print STH.fetchdict(1) print STH.fetchdict() STH = DBH.query("select * from pytest",1) print STH.fetchdict(1) print STH.fetchdict() # compare to previous dicts STH = DBH.query("select * from pytest",1) print STH.fetchrows(1) print STH.eof() print STH.fetchrows() print STH.eof() DBH['drop table pytest']




Содержание  Назад  Вперед