MySQLdb - Check if row exists Python

后端 未结 3 1075
借酒劲吻你
借酒劲吻你 2021-02-06 18:26

I am trying to check if a row exist with the same Name my database with python and can\'t quite get it here is what I am trying: (I know the connection is wokring)



        
3条回答
  •  佛祖请我去吃肉
    2021-02-06 19:15

    cursor.execute("SELECT * FROM userinfo WHERE User_Name=%s",(userid,))
    data="error" #initially just assign the value
    for i in cursor:
        data=i #if cursor has no data then loop will not run and value of data will be 'error'
    if data=="error":
        print("User Does not exist")
    else:
        print("User exist")
    

提交回复
热议问题