python连接mysql数据库,传递参数格式问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_36602742/article/details/78962323

方法1: 用%s传参

code:

sqli73 = "SELECT COUNT(*) FROM  information_schema.TABLES WHERE TABLE_NAME= %s "
cur.execute(sqli73 , (strtext70,))
如果 这样写:
cur.execute(sqli73 , strtext70)
会报错。

方法2:用.format传递参数

传递带引号的字符串

sqli73 = "SELECT COUNT(*) FROM  information_schema.TABLES WHERE TABLE_NAME={}".format("'test'")####
cur.execute(sqli73)
传递不带引号的字符串

sqli73 = "SELECT COUNT(*) FROM  information_schema.TABLES WHERE TABLE_NAME={}".format('test')####
cur.execute(sqli73)




猜你喜欢

转载自blog.csdn.net/weixin_36602742/article/details/78962323
今日推荐