Learn › Class 12 › Computer Science / Informatics Practices › Python and MySQL connectivity
Python and MySQL connectivity
Remember
- connect() → cursor() → execute() → fetchone()/fetchmany()/fetchall() → close().
- commit() saves INSERT, UPDATE and DELETE.
- Use %s placeholders with a tuple of values to prevent SQL injection.
Quick self-check
What does cursor.rowcount tell you after an UPDATE?
Check
How many rows the UPDATE changed.
Why close the connection?
Check
To free the server's resources and end the session cleanly.