扫码关注官方订阅号
记录下,防止以后忘掉
原因是在mysql 中, 字段 in 后边应该加元祖(),而现在代码中传进去的参数是个列表,造成语法错误改正:
将要传递的参数使用 join()生成一个字符串传进去,另外,在MySQL语句中,dtu_id in (%s)(格式符放进元祖括号中)
新手上路,欢迎老司机指导纠正
小伙看你根骨奇佳,潜力无限,来学PHP伐。
个人写法,供参考
db = MySQLdb.connect(*****) cursor = db.cursor() sql = "update test set name = 'test' where id in(%s)" args = [1, 2, 3] in_p = ', '.join((map(lambda x: '%s', args))) cursor.execute(sql % in_p, args) db.commit()
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
个人写法,供参考