MySQL Connector/Python 發行說明
在大多數情況下,會使用 MySQLConnection
的 cursor()
方法來實例化 MySQLCursor
物件。
import mysql.connector
cnx = mysql.connector.connect(database='world')
cursor = cnx.cursor()
也可以將 MySQLConnection
物件傳遞給 MySQLCursor
來實例化游標。
import mysql.connector
from mysql.connector.cursor import MySQLCursor
cnx = mysql.connector.connect(database='world')
cursor = MySQLCursor(cnx)
connection 引數是選填的。如果省略,則會建立游標,但其 execute()
方法會引發例外。