首页 > 解决方案 > 在 mysql 函数中返回一个布尔值并在 python 中使用它

问题描述

所以我需要的是在 MySQL 的函数中返回一个布尔值,并在 Python 中使用它作为 Python 函数中的条件。我有这个

class A:
def login():
    username: input("Username: ")
    password: input("Password: ")
    if B.user_exists(username, password):
        # do something

class B:
def user_exists(cls, username, password):
    try:
        db = cls.conection()
        cursor = db.cursor()
        cursor.execute("SELECT UserExists(%s, %s)", (username, password))
        # here it should be something to return if it's true or false
    Error:
        print("Error", Error)

注意:MySQL 的功能工作正常,我在 Datagrip 上对其进行了测试,所以这不是问题

标签: pythonmysql

解决方案


推荐阅读