To fill an array with values from SQL in Python, you can use the following code:
import mysql.connector
# establish a connection to the database
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="yourdatabase"
)
# create a cursor object
mycursor = mydb.cursor()
# execute the SQL query
mycursor.execute("SELECT chatid FROM chats")
# fetch all the results
results = mycursor.fetchall()
# create an empty array
chats_id = []
# loop through the results and append them to the array
for result in results:
chats_id.append(result[0])
# print the array
print(chats_id)
This code uses the mysql.connector module to establish a connection to the database and execute the SQL query. It then fetches all the results and loops through them to append them to an empty array. Finally, it prints the array.
Note that you need to replace yourusername, yourpassword, and yourdatabase with your own values.