__author__ = 'Administrator'
import mysql.connector
#登录上数据
cnn=mysql.connector.connect(**config)
#游标--》获取操作数据库的权限
cursor=cnn.cursor()
#增删改查
#sql='select * from student where id=%s and age>%s'
sql='select * from student'
#插入数据
sql_insert='insert into student(age,name) values(%s,%s)'
#查询的时候传参:元祖 --》如果元祖传参只有一个数据要介样(1,)
#插入数据传参:列表,字典
#data=(2,19)
data=('18','wuyue')
#data=[(16,'mm'),(19,'gg')]#列表
dict={'age':20,'name':'我是无序'}#因为字典随机,要指明一下values(%(age)s,%(name)s)
#执行语句
cursor.execute(sql)
#cursor.execute(sql_insert,data)
#cursor.executemany(sql,data)
#cursor.execute("commit")
#fetch 返回元祖数据
#fetchall 返回列表,列表里面有元祖
# 读取查询结果 类似光标处理
# 针对查询结果,如果数据只有一条用fetchone,fetchall都可以(只读一条数据)--
# 如果数据多条只用fetchone会报错 而fetchall不会(读取所有数据)
result1=cursor.fetchall()
#result=cursor.fetchone()
print(result1)
#print(result)
cursor.close()
cnn.close()
import mysql.connector
#登录上数据
cnn=mysql.connector.connect(**config)
#游标--》获取操作数据库的权限
cursor=cnn.cursor()
#增删改查
#sql='select * from student where id=%s and age>%s'
sql='select * from student'
#插入数据
sql_insert='insert into student(age,name) values(%s,%s)'
#查询的时候传参:元祖 --》如果元祖传参只有一个数据要介样(1,)
#插入数据传参:列表,字典
#data=(2,19)
data=('18','wuyue')
#data=[(16,'mm'),(19,'gg')]#列表
dict={'age':20,'name':'我是无序'}#因为字典随机,要指明一下values(%(age)s,%(name)s)
#执行语句
cursor.execute(sql)
#cursor.execute(sql_insert,data)
#cursor.executemany(sql,data)
#cursor.execute("commit")
#fetch 返回元祖数据
#fetchall 返回列表,列表里面有元祖
# 读取查询结果 类似光标处理
# 针对查询结果,如果数据只有一条用fetchone,fetchall都可以(只读一条数据)--
# 如果数据多条只用fetchone会报错 而fetchall不会(读取所有数据)
result1=cursor.fetchall()
#result=cursor.fetchone()
print(result1)
#print(result)
cursor.close()
cnn.close()