How to execute multi query in python?

前端 未结 1 974
小鲜肉
小鲜肉 2021-01-21 21:32

I want to execute the sql_query given in below function and doing this way :

def get_globalid(self): 
    cursor = self.connect()
    sql_query = \"REPLACE INTO          


        
1条回答
  •  别那么骄傲
    2021-01-21 22:23

    mysql-python can't execute semicolon separated multiple query statement. If you are looking for last_insert_id you can try with this:

    conmy = MySQLdb.connect(host, user, passwd, db)
    cursor = conmy.cursor()
    sql_query = "REPLACE INTO globalid (stub) VALUES ('a')"
    cursor.execute(sql)
    last_insert_id = conmy.insert_id()
    conmy.close()
    

    0 讨论(0)
提交回复
热议问题