Interfacing_Python_with_MySQL_Questions-2 MARKS
Interfacing_Python_with_MySQL_Questions-2 MARKS
8. 8. Mention two common exceptions raised while working with MySQL in Python.
- `mysql.connector.errors.InterfaceError` and `mysql.connector.errors.DatabaseError`.
9. 9. What are placeholders in MySQL queries, and how are they used in Python?
- Placeholders are symbols like `%s` used in parameterized queries to avoid SQL
injection.
For example:
cursor.execute("INSERT INTO table_name (col1) VALUES (%s)", (value,))
10. 10. Write the command to create a cursor object in MySQL Python connectivity.
- `cursor = connection.cursor()`
11. 11. What is the difference between `fetchone()` and `fetchall()` methods?
- `fetchone()` retrieves a single record, whereas `fetchall()` retrieves all records from the
query result.
13. 13. Write the command to delete a record from a table in MySQL using Python.
- Example:
14. 14. How can you handle errors during MySQL operations in Python?
- Use a `try-except` block to catch exceptions such as `mysql.connector.Erro