1. First of all, the Python database interface supports a lot of databases. You can choose the database that suits your project:.
2. Then you can access the Python database interface and API to view a detailed list of supported databases. You need to download different DB API modules for different databases. For example, if you need to access Oracle database and MySQL data, you need to download Oracle and MySQL database modules. DB-API is a specification. It defines a series of necessary objects and database access methods to provide consistent access interfaces for a variety of underlying database systems and a variety of database interface programs. Python's DB-API implements interfaces for most databases. After using it to connect to each database, you can operate each database in the same way. Python DB-API usage process:.
3. MySQLdbMySQLdb is an interface for Python to connect to the Mysql database. It implements the Python database API specification V2.0 and is based on the MySQL C API. Commonly used functions Python DB API 2.0 provides two methods for transactions:
4, and then 5cursor methods used to execute commands:.
5. The last 6 methods used by cursor to receive return values: fetchall(self) receives all return result lines. fetchmany(self, size=None) receives size return result lines. If the value of size is greater than the number of result rows returned, cursor.arraysize data will be returned. fetchone(self) returns one result row. rowcount This is a read-only property and returns the number of rows affected after executing the execute() method. . scroll(self, value, mode=relative) moves the pointer to a certain row; if mode=relative, it means moving the value bar from the current row; if mode=absolute, it means moving the value bar from the first row of the result set.
The above is the detailed content of How to connect to the database in python_Tutorial on connecting to the database in python. For more information, please follow other related articles on the PHP Chinese website!