美文网首页
python下MySQL的使用

python下MySQL的使用

作者: 不懒狮Blaise | 来源:发表于2017-12-20 16:17 被阅读0次

mysql连接

    conn_game = MySQLdb.connect(host=app.config["DATABASE_IP"], user=app.config["DATABASE_USER"], 
    passwd=app.config["DATABASE_PWD"], db=app.config["DATABASE_LOGIN_DB"])

全部查询

    cursor = conn_game.cursor()
    cursor.execute('select id, pid, value from `tb` where id=%s', (uid,))
    prop = cursor.fetchall()

单个查询

  cursor = conn_game.cursor()
  cursor.execute('select id, pid, value from `tb` where id=%s', (uid,))
  row = cursor.fetchone()

更新数据

  cursor = conn_login.cursor()
    sql = "update `tb1` set device=CONCAT(device,'DEL') where id  in (select id from `tb2` where uid in (%s));"
    cursor.execute(sql, (uid,))
    conn_login.commit()
    cursor.close()

相关文章

网友评论

      本文标题:python下MySQL的使用

      本文链接:https://www.haomeiwen.com/subject/uyigwxtx.html