python 用mysqldb方式操作数据库
来源:互联网 发布:网吧电影软件 编辑:程序博客网 时间:2024/04/30 12:22
# -*- coding: utf-8 -*-from User import Userimport time, MySQLdb#连接conn = MySQLdb.connect(host='localhost', user='root', passwd='root', db='test', charset='utf8')cursor = conn.cursor()#写入# sql = "insert into Users values(null, %s, %s)"# for i in range(0, 10):# param = ('liuruichao', 'nicai')# result = cursor.execute(sql, param)# print (result)# conn.commit()# cursor.close()# conn.close()#更新# sql = 'update Users set username=%s where id = %s'# param = ('buzhidao', 2)# result = cursor.execute(sql, param)# print (result)# conn.commit()# cursor.close()# conn.close()#删除# sql = 'delete from Users where id = %s'# param = (2)# result = cursor.execute(sql, param)# print (result)# conn.commit()# cursor.close()# conn.close()#查询list = []sql = 'select * from Users'cursor.execute(sql)rs = cursor.fetchall()for id, username, password in rs: print ('id : {}, username : {}, password : {}'.format(id, username, password)) user = User() user.id = id user.username = username user.password = password list.append(user)cursor.close()conn.close()print ('总共有{}人'.format(len(list)))
0 0
- python 用mysqldb方式操作数据库
- Python MYSQLdb操作数据库
- MySQLdb和Python数据库操作
- python使用MySQLdb操作数据库
- python操作MySQL数据库(MySQLdb
- python数据库操作 - PyMySQL,MySQLdb
- MySQLdb:Python 操作 MySQL 数据库
- python 通过mysqldb 操作mysql数据库
- 【python系列】mysqldb模块操作数据库
- python操作数据库模板 MySQLdb模块
- python MySQLdb API的数据库更新操作
- 【MySQLdb模块】Python操作MySQL数据库
- python利用MySQLdb操作远程数据库
- python数据库操作模块MySQLdb简介
- python下使用MySQLdb操作MYSQL数据库
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- [Python]MySQLdb for Python使用指南/Python的数据库操作
- 栈对象,堆对象,对象指针
- 我喜欢阳光洒在脸上的感觉,因为这里有过太多的泪水
- AE内存图层
- Spotify称赶超苹果只是时间早晚的事
- Algorithm学习笔记 --- 单调队列
- python 用mysqldb方式操作数据库
- WIN7 SP1 0x8007000D错误
- poj1365
- 技巧:Linux动态库与静态库制作及使用详解
- android ndk 无法访问android.app.Activity
- UItabBar的一个致命错误——没使用容器
- gethostbyname返回错误Operation not permitted解决办法
- c程序--打渔晒网问题
- git 切换分支