码迷,mamicode.com
首页 > 数据库 > 详细

Pymysql

时间:2021-05-24 12:10:38      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:code   exec   指定   _id   pymysql   port   nta   modify   please   

Pymysql


一、模块商城pip介绍

  • pip是个可执行文件,该命令可帮助我们管理第三方模块(将该文件下载到本地,并解压到指定目录)
  • python2,默认无pip命令;python3,默认下载pip命令(但需手动添加到环境变量中)
  • pip相当于统一管理第三方模块的模块商城(pypi.python.org/pypi)
  • 更新pip: python -m pip install --upgrade pip
  • other: yum install xxx; apt-get install xxx; brew install xxx; easyinstall xxx

二、pymysql模块的使用

sql injection: Because the statement after the character(--) be identified to invalid statement

import pymysql
# establish a link
conn = pymysql.connect(host="127.0.0.1", post=3306, user="root", passwd="666", db="datebase_name", charset="utf8")

# establish a cursor
cursor = conn.cursor()		# Equate to create a jurisdiction to operate mysql

# add/delete/modify/show
cursor.excute("sql_statement")		# Ruturn a value, the rows modified
conn.commit()		# commit the modification to mysql

# When convey args, don‘t permit to concat string
inp = input("please input your class name: >>>")
r = cursor.execute("insert into class(caption) values(%s)", inp)

g = [("arno", "male"), ("kristy", "female")]
r = cursor.executemany("insert into student(name, gender) values(%s, %s)", g)

# show
r = cursor.execute("select nid,name from student")
print(cursor.fetchall())		# cursor.fetchone; Take out the values found in terms of the scroll

# shift scroll
cursor.scroll(0, mold="absolute")		# Come back the start of the file
cursor.scroll(1, mold="relative")		# Go down to the file

# Modify the value‘s type found
cursor = conn.cursor(cursor=pymysql.cursor.DictCursor)

# Get the id newly created
new_id = cursor.lastrowid()		-- get the the id of lastrow

cursor.close()
conn.close()

Pymysql

标签:code   exec   指定   _id   pymysql   port   nta   modify   please   

原文地址:https://www.cnblogs.com/xiaokaibiubiu/p/14773134.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!