美文网首页程序员
day 6(python notes)

day 6(python notes)

作者: 君宝儿 | 来源:发表于2016-05-17 11:09 被阅读33次

note 1:python操作数据库,分别是数据库连接对象,游标。打开数据库时返回conn对象,是数据库连接对象connect,conn=sqlite3.connect(host,user,passwd,db)
host:连接数据库的服务器主机名,默认localhost。user:连接数据库用户名,默认当前用户。db:连接的数据库名。conn对象有commit()方法,表示事务提交。rollback()事务回滚。close()关闭数据库连接。

note 2:游标cursor是数据库管理系统为用户开设的一个数据缓冲区,存放sql语句的执行结果,每个游标区都有一个名字,用户可以用sql语句逐一从游标中获取记录,进行操作处理。

note 3:定义游标cu=conn.cursor()。游标对象有如下操作,excute()执行sql语句。excutemany执行多条sql语句.fetchone()从结果中取出一条记录,并将游标指向下一条记录。fetchmany()从结果中取出多条记录。fetchall()从结果中取出所有记录。scroll()游标滚动。close()关闭游标。

note 4:操作数据库过程:1.用db.connect创建数据库连接,返回连接对象conn。
2.用conn.cursor创建游标对象cu。通过cu.excute查询数据库,用cu。fetchall等方法返回查询结果。用conn.commit修改数据库。关闭cu,conn。

note 5:操作mysql数据库需要使用mysqldb接口,从sourceforge.net/projects/mysql-python/下载与Python版本对应的mysql-Python-py2.7文件。

相关文章

  • day 6(python notes)

    note 1:python操作数据库,分别是数据库连接对象,游标。打开数据库时返回conn对象,是数据库连接对象c...

  • day 4(python notes)

    note 1:声明类 class 类名:对象定义对象p=类名()。note 2:类属性,属性名前加""表明为私有...

  • day 3(python notes)

    note 1:python中函数声明 def 函数名(形参列表): 。函数没有标明函数的开始结束花括号。函数名下的...

  • day 2(python notes)

    介绍Python的几种序列,字符串,列表,元组 note 1:list=[1,1.3,"a"] list[1:2]...

  • day 5(python notes)

    note1:继承通过派生类和基类实现。基类称为父类,派生类称为子类。继承语法如下:class SubClassNa...

  • Python 笔记

    【2017.04.20】 List Comprehension Notes of Python Tutorial:...

  • Coal Bank 纸厂的线性规划

    Python Day 6: Linear Optimization with Paper Company Last...

  • Python Notes (6) - Advanced Topi

    The note will introduce more advanced points about what w...

  • Functional Python Programming -

    Learning notes on Functional Python Programming Book: Fun...

  • Python Notes:Day1

    1.python 中单斜杠‘/’和双斜杠'//' a = 3b = 2print (a/b) 输出1.5 prin...

网友评论

    本文标题:day 6(python notes)

    本文链接:https://www.haomeiwen.com/subject/eycirttx.html