当前位置:首页 > Python教程 > python技巧

python查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#coding=utf-8
import MySQLdb
conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd='',db='test',charset='utf8')
cursor = conn.cursor()
sql = "select * from orders"
cursor.execute(sql)
 
#获取总记录数
print cursor.rowcount
 
#获取一条数据
rs = cursor.fetchone()
print rs
 
#获取3条数据,将从第二条开始
rs = cursor.fetchmany(3)
print rs
 
#获取所有数据,返回所有的数据
rs = cursor.fetchall()
print rs
 
cursor.close()
conn.close()

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!