X-Intend[超级打算]
每个人都有自己的想法,哪怕仅仅一瞬间~!

MySQL-Python

KingFo 于 2008-08-15 00:21:32 发表  开发者

http://mysql-python.sourceforge.net/

 记录下

 

  1. #!/usr/bin/env python  
  2. # -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码  
  3. #=========================================================================  
  4. #  
  5. # NAME: Python MySQL test  
  6. #  
  7. # AUTHOR: benyur  
  8. # DATE  : 2004-12-28  
  9. #  
  10. # COMMENT: 这是一个python连接mysql的例子  
  11. #  
  12. #=========================================================================   
  13. """  
  14.  ***** This is a MySQL test *****  
  15.    
  16.  select:  
  17.   conn=Connection()  
  18.   conn.select_db('test')  
  19.   cur=conn.cursor()  
  20.   cur.execute('select * from user')  
  21.   cur.scroll(0)  
  22.   row1=cur.fetchone()  
  23.   row1[0]  
  24.   row1[1]  
  25.   row1[2]  
  26.     
  27.  insert:  
  28.   cur.execute('insert into user (name,passwd) values('benyur','12345')')  
  29.   cur.insert_id()  
  30.     
  31.  update:  
  32.   cur.execute('update user set passwd='123456' where name='benyur'')  
  33.     
  34.  delete:  
  35.   cur.execute('delete from user where id=2')  
  36.    
  37.  **********************************  
  38. """ 
  39.  
  40. from MySQLdb import *  
  41.  
  42. def conn():  
  43.  conn=Connection()  
  44.  conn.select_db('test')  
  45.  cur=conn.cursor()  
  46.  cur.execute('select * from user')  
  47.  cur.scroll(0)  
  48.  row1=cur.fetchone()  
  49.  row1[0]  
  50.  row1[1]  
  51.  row1[2]  
  52.  
  53. def usage():  
  54.  print __doc__  
  55.  
  56. if __name__=='__main__':  
  57.  usage()  

 

被阅 312 次, 0投一票
    1 / 0 / 0 | « 1 » |
    1 / 0 / 0 | « 1 » |
  • 看完了要说点啥么?
  • 昵称 (不填说不了话)
  • 信箱地址 (不会被公开,但是不填也说不了话)
  • 网址 (这个不填也成)

Google 网上论坛
订阅 XIntend
电子邮件:
访问此论坛

文章分类

站点统计

  • 文章总数: 87 篇
  • 评论总数: 6 条
  • 附件总数: 53 个
  • 留言总数: 0 份
  • 建站日期: 2008-1-1
  • 访问总数: 96529 人次

最新留言

赞助商

友情链接

Design by Free CSS Templates & TiSkin, Powered by Roclog v3.2.13

滇ICP备05000389号, Copyright © 2007 X-Intend[超级打算]. All rights reserved.