发布网友 发布时间:2022-04-24 04:27
共4个回答
懂视网 时间:2022-04-08 13:19
#coding=utf-8 2 import MySQLdb 3 conn = MySQLdb.Connect(host = ‘127.0.0.1‘,port=3306,user=‘root‘,passwd=‘‘,db=‘test‘,charset=‘utf8‘) 4 cursor = conn.cursor() 5 6 try: 7 #插入数据 8 sql_insert = "insert into orders(order_id,product_id) values (777,777)" 9 cursor.execute(sql_insert) 10 print cursor.rowcount 11 12 #修改数据 13 sql_update = "update orders set order_id = 99999 where id=12" 14 cursor.execute(sql_update) 15 print cursor.rowcount 16 17 #删除数据 18 sql_delete = "delete from orders where id = 3" 19 cursor.execute(sql_delete) 20 print cursor.rowcount 21 22 #提交 23 conn.commit() 24 except Exception as e: 25 print e 26 conn.rollback() 27 28 #关闭指针和连接 29 cursor.close() 30 conn.close()
python常用sql语句
标签:
热心网友 时间:2022-04-08 10:27
select_sql = "SELECT * FROM mysoftware WHERE Project_ID='%s' AND Test_ID='%s'"%(self.MyMessage[0], self.MyMessage[1])
print(select_sql)
mySw = MySQL.GetInfoFromMySQL(select_sql)
- -虽然基本不懂sql,但是百度了下,我这样写貌似是可用的,能够查询的到正确的数据~~
热心网友 时间:2022-04-08 11:45
>>> base = """("%(k)s" = '%(v)s')"""
>>> print ' and '.join([base % dict(k=k, v=v) for k,v in dict(name='tim', email='tim@126.com').items()])
("email" = 'tim@126.com') and ("name" = 'tim')
>>>
另外: 强烈建议不采用拼接字符串的方式定义SQL,而是采用参数
热心网友 时间:2022-04-08 13:19
AND两侧是不是应该有个空格 什么的呢?