Advertisement

MySQL数据库通过Python实现查询功能封装(十二)

阅读量:

数据查询操作实现

编写testSelectOne.py文件,用于检索单个学生的信息

复制代码
 #encoding=utf8

    
 import MySQLdb
    
 try:
    
     conn=MySQLdb.connect(host='localhost',port=3306,db='test1',user='root',passwd='mysql',charset='utf8')
    
     cur=conn.cursor()
    
     cur.execute('select * from students where id=7')
    
     result=cur.fetchone()
    
     print result
    
     cur.close()
    
     conn.close()
    
 except Exception,e:
    
     print e.message
    
    
    
    

多行数据查询方法

编写testSelectMany.py脚本文件,用于检索单条学生数据信息

复制代码
 #encoding=utf8

    
 import MySQLdb
    
 try:
    
     conn=M

全部评论 (0)

还没有任何评论哟~