1. Establishing a database connection
Import MySQLdb
Conn=mysqldb.connect (host= "localhost", user= "root", passwd= "sa", db= "MyTable")
Cursor=conn.cursor () Using a Connection object to get a cursor object
2. Perform database operations
N=cursor.execute (Sql,param)
Use the method provided by the cursor to do the work. These methods include two main classes: 1. Execute command, 2. Receive return value
3. Cursor used to execute the command method:
Callproc (self, procname, args): Used to execute stored procedure, received parameter is stored procedure name and parameter list, return value is the number of rows affected
Execute (Self, query, args): Executes a single SQL statement, receives the parameters for the SQL statement itself and the parameter list used, and returns the number of rows affected
Executemany (self, Query, args): Executes a heads-up SQL statement, but repeats the parameters in the list of parameters, with the returned value being the number of rows affected
Nextset (self): move to the next result set
Python database connection operation cursor ()