zoukankan      html  css  js  c++  java
  • python操作Mysql数据库

    代码:

    import MySQLdb
    
    conn=MySQLdb.connect(host='127.0.0.1', user='root', passwd='root', db='test', port=3306)
    cur=conn.cursor()
    row = cur.execute('select * from stu')
    # print affectRow
    result = cur.fetchmany(row)
    for line in result:
        print line
    
    cur.close()
    conn.close()

    简单讲解其中用到的函数

    MySQLdb.connect() 方法是连接数据库

    conn.cursor() 方法是获取游标

    cur.execute() 方法是执行sql语句,返回结果集行数

    cur.fetchmany() 方法是从结果集中获取结果,参数执行获取的行数,返回值为获取结果

  • 相关阅读:
    11.29
    11.28
    11.24
    11.21
    11.17
    11.15
    11.14
    11.9
    11.5
    11.3
  • 原文地址:https://www.cnblogs.com/lit10050528/p/4150690.html
Copyright © 2011-2022 走看看