SQL 查询在控制台中有效,但在 python 中无效 [英] SQL query works in console but not in python

查看:61
本文介绍了SQL 查询在控制台中有效,但在 python 中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 sql 查询时遇到问题,它在控制台中运行良好,但是当我在 python 中实现时,它似乎运行良好,没有错误,但是当我检查数据库时,它没有运行,但在控制台中它确实可以正常工作,没有当我检查数据库时出现错误,数据在那里......我使用的查询完全相同.

Hi im having issues with a sql query it works perfect in console, but when i implement into python it seems to work perfect no errors but when i check the database it hasnt worked, yet with the console it does work the same no errors yet when i check db the data is there... exact same query i use.

有什么想法吗?

UPDATE ex SET fbsiteurl = stringvarible, fbsitesource = '' WHERE id = 23123;

在蟒蛇中:

 cur = con.cursor()
 sqlquery = "UPDATE ex SET fbsiteurl = '"+somevarible+"', fbsitesource =        '"+somevarible+"' WHERE id = %d;" % recordid                                
 print sqlquery
 cur.execute(sqlquery)

查询在打印时显示正常,没有问题,如果我复制打印出来并将其粘贴到 mysql 控制台,它每次都可以正常工作,只是来 python,它表现得像它一样工作,但确实是 0_o

query shows up fine in print no issues, if i copy the print out and paste it into a mysql console it works perfect everytime, just come python it acts like it works but dosnt really 0_o

推荐答案

connection.autocommit(),或者你需要做connection.commit()

connection.autocommit(), or you need to do connection.commit()

这篇关于SQL 查询在控制台中有效,但在 python 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆