Python连接数据库
来源:互联网 发布:村上作品推荐 知乎 编辑:程序博客网 时间:2024/06/16 00:12
import MySQLdb#查询conn = MySQLdb.Connect(host='127.0.0.1',port=3306,user='root',passwd='123456',db='IMOOC',charset='utf8')cur = conn.cursor()sql="select * from user"cur.execute(sql)rs = cur.fetchall()for row in rs: print 'userid=%d,username=%s'%rowcur.close()conn.close()
#更新删除
sql_insert = 'insert into stud(userid, username) values("12","name12")'sql_upudate = 'update stud set username="name19" where userid="9"'sql_insert = 'delete from stud where userid<"3"'try: cursor.execute(sql_insert) print cursor.rowcount cursor.execute(sql_upudate) print cursor.rowcount cursor.execute(sql_insert) print cursor.rowcount conn.commit()except Exception as e: print e conn.rollback()
阅读全文
0 0
- python连接mysql数据库
- python连接mysql数据库
- python连接MySQL数据库
- Python连接mysql数据库
- python--连接数据库篇
- python连接mysql数据库
- Python连接mysql数据库
- Python连接mysql数据库
- Python连接MySql数据库
- Python数据库的连接
- Python 连接mysql数据库
- Python连接数据库-pyodbc
- Python连接数据库
- Python 连接数据库
- python连接mysql数据库
- Python数据库的连接
- Python连接mysql数据库
- Python连接mysql数据库
- Centos6与Centos7防火墙设置与端口开放的方法
- 260. Single Number III
- 【JZOJ 5260】 区间第k小
- .NET Framework 的容器
- 华为硬件通用类笔试总结
- Python连接数据库
- InnoDB存储引擎
- 数据结构之图篇
- LabVIEW 读取 DLL 函数
- 线程的生命周期
- 单例模式(Singleton)
- Java面向对象
- 判断题(PAT-1061)
- 循环缓存区之C++实现