[Python] When dealing with Python and SQL should I have separate scripts for INSERTING,...

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to SQL and Python. I have been learning how to manipulate data using python instead of directly from SQL but I am logically thinking that since I have already ran a script to add data I should have different scripts for other actions like:

    1. print
    2. alter
    3. inserting

    this part should insert one record into the test database.
    ​

    mycursor = mydb.cursor()
    sql = 'INSERT INTO users (email, bio, country) VALUES (%s, %s, %s)'
    val = ('boss@gmail.com', 'SQL is life', 'ZW')
    mycursor.execute(sql, val)
    mydb.commit()
    print(mycursor.rowcount, "record inserted.")


    when I want to then print the data base
    ​

    sql = 'SELECT * FROM users'
    mycursor.execute(sql)

    db_content = mycursor.fetchall()
    for record in db_content:
    print(record)


    I am getting an error like this after adding the print part

    self._connection.cmd_query(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^
    self._stmt_partition["mappable_stmt"],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    read_timeout=self._read_timeout,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    write_timeout=self._write_timeout,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )


    I was expecting to see my data pulled from mysql database in the console

    Continue reading...

Compartilhe esta Página