from pymysql import *
def main():
find_name=input("请输入物件名称:")
#创建Connection链接
conn=connect(host='localhost',port=3306,user='root',password='mysql',databse='stock',charset='utf-8')
#获取Cursor对象
cs1=conn.cursor()
#非安全的方式
##输入"or 1=1 or"(双引号也要输入)
#sql='select * from goods where name="%s"'%find_name
#print("""sql===>%s<==="""%sql)
##执行selcet语句,并返回受影响的行数:查询所有数据
#count=csl.execute(sql)
#安全方式
#构造参数列表
params=[find_name]
#执行selcet语句,并返回受影响的行数:查询所有数据
count=csl.execute('select * from goods where name=%s',params)
#注意:
#如果要是有多个参数,需要进行参数优化
#那么params=[数值1,数值2...],此时sql语句中有多个%s即可
#打印受影响的行数
print(count)
#获取查询的结果
#result=csl.fetchall()
result=csl.fetchall()
#打印查询结果
print(reslut)
```