Python Telegram Bot: Running MySQL Queries with Two Conditions

I’m developing a Python Telegram bot that connects with a MySQL database, and I need help constructing a query that verifies two conditions simultaneously. Specifically, I want to select records where two different criteria are met. Below is an example I devised:

data_result = connection.execute_query("SELECT * FROM user_records WHERE is_active = ? AND account_balance = ?", (active_flag, current_amount))

Could someone review this approach and advise if any adjustments are necessary to properly filter data using two parameters?

hey, your code seems ok but some mysql drivers need %s insted of ? check that and make sure your datatypes match device colums. also be cautious of sql injections if combining any other user input.

The implementation appears largely correct, but it is important to confirm the placeholder syntax for the specific MySQL driver you are using. In my experience, many libraries such as mysql.connector expect %s as the placeholder rather than a question mark. I also recommend verifying that the variable types and values passed match the corresponding database column definitions. Adding error handling around the query execution can also help diagnose any unforeseen issues during runtime.