1、首先建立 users 表:
2、增删改查,代码如下:
get 和 query 都可以用来查询,但是get只能查询一个结果,query是拿到一个list列表
import torndb
db = torndb.Connection(host='127.0.0.1', database='busy', user='root', password='111111')
sql1 = 'select * from users where userId=%d'%(1)
sql2 = 'select * from users'
#sql3 = 'insert into users(userId, userName, passWord) values(%d, "%s", "%s")'%(3, 'bobo', '123456')
sql4 = 'update users set passWord="%s" where userId=%d'%('111111', 3)
#sql5 = 'delete from users where userId=%d'%(3)
a = db.get(sql1)
b = db.query(sql2)
#db.execute(sql3)
db.execute(sql4)
#db.execute(sql5)
print(a)
print(b)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/16593.html