您的位置:首页 > 汽车 > 时评 > 动漫制作工资一般多少_html素材图片_网络推广及销售_网店推广平台有哪些

动漫制作工资一般多少_html素材图片_网络推广及销售_网店推广平台有哪些

2025/4/18 15:38:26 来源:https://blog.csdn.net/2503_90633075/article/details/146558115  浏览:    关键词:动漫制作工资一般多少_html素材图片_网络推广及销售_网店推广平台有哪些
动漫制作工资一般多少_html素材图片_网络推广及销售_网店推广平台有哪些

pymysql

1、下载pymysql 库(第三方机构)

方法一:dos下安装:

pip3  install   pymysql  或pip   install  pymysql

图片

图片

方法二:在pycharm中下载

图片

二.使用pymysql

(1)数据安装好,能连接

图片

(2)连接数据库

图片

图片

(1)连接方式:pymysql.Connection 或者pymysql.connect 

(2)包含内容

a.host 主机:填写IP地址

b.user  数据库用户名

c.password 或passwd  密码:

d.databases  或db  库名

e.port  端口  :默认3306

f.charset ='utf8'    编码格式

案例:

db=pymysql.Connection(host="192.168.157.128",user="root",password="123456",database="test",port=3306,charset='utf8')

图片

(2)将连接内容设置成一个变量,然后创建一个游标对象

db.cursor

(3)使用游标对象去执行sql语句

(4)在根据需要显示内容使用 fetchone,fetchall,fetchmany

代码:

import  pymysql #导入pymysql
lj=pymysql.connect(    host="192.168.1.210",user="root",passwd="123456",port=3306,database="hh",charset="utf8"
)  #pymysql连接参数
yb=lj.cursor() #创建游标对象
sql="select  * from  student" #sql语句
yb.execute(sql) #执行sql语句
# one=yb.fetchone() #查看执行一行数据
# print(one)
# many=yb.fetchmany(size=3)
# print(many)
all=yb.fetchall()
print(all)

二.pymysql操作数据库的增删改查

1.删除

import  pymysql #导入pymysql
lj=pymysql.connect(host="192.168.1.210",user="root",passwd="123456",port=3306,database="hh",charset="utf8"
)  #pymysql连接参数
yb=lj.cursor() #创建游标对象
#删除
sql="delete  from  student where id=1 "
yb.execute(sql)

2.插入数据

import  pymysql #导入pymysql
lj=pymysql.connect(host="192.168.1.210",user="root",passwd="123456",port=3306,database="hh",charset="utf8"
)  #pymysql连接参数
yb=lj.cursor() #创建游标对象
#插入数据:
sql="INSERT into  student(id)  VALUES (1)"
yb.execute(sql)

3.修改数据

import  pymysql #导入pymysql
lj=pymysql.connect(host="192.168.1.210",user="root",passwd="123456",port=3306,database="hh",charset="utf8"
)  #pymysql连接参数
yb=lj.cursor() #创建游标对象
#插入数据:
sql="UPDATE  student  set  id=30 where id=20;"
yb.execute(sql)

案例2:

import  pymysql #导入pymysql
lj=pymysql.connect(host="192.168.1.210",user="root",passwd="123456",port=3306,database="hh",charset="utf8"
)  #pymysql连接参数
yb=lj.cursor() #创建游标对象
#插入数据:
sql="UPDATE  student  set  id=40 where id=30;"
yb.execute(sql)
sql2="select  * from  student"
yb.execute(sql2)
print(yb.fetchall())

三.数据库封装

import pymysql
class  Sjk(object):def __init__(self,host,user,passwd,port,database):self.host=hostself.user=userself.passwd=passwdself.port=portself.database=databasedef lj(self):ljsql= pymysql.connect(host=self.host,user=self.user,port=self.port,passwd=self.passwd,database=self.database,charset="utf8")return ljsqldef one(self,sql1):s=self.lj()yb=s.cursor()yb.execute(sql1)print(yb.fetchone())def many(self, sql2,x):s = self.lj()yb = s.cursor()yb.execute(sql2)print(yb.fetchmany(size=x))def all(self, sql3):s = self.lj()yb = s.cursor()yb.execute(sql3)# print(yb.fetchall())sy=yb.fetchall()for i  in sy:print (i)
if __name__ == '__main__':dx=Sjk(host="192.168.1.210",user="root",passwd="123456",port=3306,database="hh")# dx.one("select *  from student")# dx.many("select *  from student",3)dx.all("select *  from student")

在测试,你可以通过数据库造数据,删除数据,修改数据,

断言

1.查询后台数据

2.造数据

3.删除数据,让数据不冗余

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com