๐ This question is part of the full practice set
Start free โ 5 days
Subjects โบ Computer Science โบ Python-MySQL Connectivity
Python-MySQL Connectivity
๐ How to approach this chapter
In a typical paper this chapter carries about 4.1 marks. Fixed code template - learn once.
- What the questions look like: a 2-5 mark program that connects to MySQL and inserts, updates, deletes, or displays rows, or a 1-mark MCQ on cursor / fetch / commit. The exam gives username, password, host and database name.
- Template: import mysql.connector as sq; con = sq.connect(host="localhost", user="admin", passwd="root", database="SCHOOL"); cur = con.cursor(); cur.execute("SELECT ..."); rows = cur.fetchall(); for r in rows: print(r); con.close().
- fetchone() returns one row, fetchmany(n) n rows, fetchall() all remaining rows (as a list of tuples); cur.rowcount gives the number of rows affected/fetched. INSERT, UPDATE and DELETE need con.commit() or the change is not saved.
- Putting values in a query: "INSERT INTO t VALUES (%s, %s)" with cur.execute(query, (a, b)), or the format() / f-string way - either is accepted. Check the quotes around string values.
You can try the first few questions here. Start free for 5 days to open everything.
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days