python DB API 规范
python操作DBMS
1. 引入API模块
2. 与数据库建立连接;
3. 执行SQL语句
4. 关闭数据库连接
使用MySQL-connector
1. Connection
* host, user, passwd, port对应Ip, 用户名,密码,端口
* db.close()
* db.cursor()
* db.begin()
* db.commit db.rollback
2. Cursor
* cursor.execute(query_sql)
* cursor.fetchone()
* cursor.fetchall()
* cursor.fetchmany(n)
* cursor.rowcount
* cursor.close()
对数据表进行增删改查
import tracebacktry: sql = "INSERT INTO player (team_id, player_name, height) VALUES (%s, %s, %s)" val = (1003, "约翰-科林斯", 2.08) cursor.execute(sql, val) db.commit() print(cursor.rowcount, "记录插入成功。")except Exception as e: