Python导入数据库错误,运用try的方式始终报F但是不报错 5
代码如下:connect=pymysql.Connect(host='localhost',port=3306,user='root',passwd='root',db=...
代码如下: connect = pymysql.Connect( host='localhost', port=3306, user='root', passwd='root', db='demo', charset='utf8') cursor = connect.cursor() try: sql = "INSERT INTO znzp (name, gsmc, zwyx, gzdd) VALUES ('%s', '%s', '%s', '%s')" %(name1, gsmc, zwyx, gzdd) cursor.execute(sql) connect.commit() print('T') except: print("F")是我哪里写错了吗?
展开
1个回答
展开全部
import pymysql
connect = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='root',
db='demo',
charset='utf8')
cursor = connect.cursor()
cursor.execute("use demo") #使用数据库
try:
sql = "INSERT INTO znzp (name, gsmc, zwyx, gzdd) VALUES (%s, %s, %s, %s)" %(name1, gsmc, zwyx, gzdd)
cursor.execute(sql)
connect.commit()
print('T')
except:
print("F")
你再试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询