import pymysql
username = 'xaw'
pwd = '123456'
conn = pymysql.connect(
host='127.0.0.1',
user='root',
password='666660',
database='database_2',
port=3306,
)
cur = conn.cursor()
sql = "select * from user where name = '{}' and pwd = '{}' ".format(username, pwd)
rescount = cur.execute(sql)
print(rescount)
cur.close
conn.close
import pymysql
username = 'xaw'
pwd = '123456'
conn = pymysql.connect(
host='127.0.0.1',
user='root',
password='666660',
database='database_2',
port=3306,
)
cur = conn.cursor()
sql = "select * from user where name = %s and pwd = %s "
rescount = cur.execute(sql,(username,pwd))
print(rescount)
cur.close
conn.close
import pymysql
id = 5
username = 'zwh0'
pwd = '1234560'
conn = pymysql.connect(
host='127.0.0.1',
user='root',
password='666660',
database='database_2',
port=3306,
)
cur = conn.cursor()
sql = "insert into user values(%s,%s,%s,001)"
rescount = cur.execute(sql,(id,username,pwd))
print(rescount)
conn.commit()
cur.close
conn.close
import pymysql
conn = pymysql.connect(
host='127.0.0.1',
user='root',
password='666660',
database='database_2',
port=3306,
)
cur = conn.cursor()
sql = "select * from user"
rescount = cur.execute(sql)
print(rescount)
row = cur.fetchone()
print(row)
row = cur.fetchone()
print(row)
row = cur.fetchone()
print(row)
cur.close
conn.close
import pymysql
conn = pymysql.connect(
host='127.0.0.1',
user='root',
password='666660',
database='database_2',
port=3306,
)
cur = conn.cursor()
sql = "select * from user"
rescount = cur.execute(sql)
print(rescount)
rows = cur.fetchmany(1)
print(rows)
rows = cur.fetchmany(2)
print(rows)
cur.close
conn.close
import pymysql
conn = pymysql.connect(
host='127.0.0.1',
user='root',
password='666660',
database='database_2',
port=3306,
)
cur = conn.cursor(cursor=pymysql.cursors.DictCursor)
sql = "select * from user"
rescount = cur.execute(sql)
print(rescount)
rows = cur.fetchmany(1)
print(rows)
rows = cur.fetchmany(2)
print(rows)
cur.close
conn.close
|