filmov
tv
Lesson - 54 : Python Advanced - Python Database Access : MySQL Query
Показать описание
**************************************************
**************************************************
Python Database Access : MySQL Query:
To query data in a MySQL database from Python, you need to do the following steps:
1. Connect to the MySQL Database, you get a MySQLConnection object.
2. Instantiate a MySQLCursor object from the the MySQLConnection object.
3. Use the cursor to execute a query by calling its execute() method.
4. Use fetchone() , fetchmany() or fetchall() method to fetch data from the result set.
5. Close the cursor as well as the database connection by calling the close() method of the corresponding object.
6. We will show you how to use fetchone() , fetchmany() , and fetchall() methods in more detail in the following sections.
Example :
dbconfig = read_db_config()
conn = MySQLConnection(**dbconfig)
**************************************************
Python Database Access : MySQL Query:
To query data in a MySQL database from Python, you need to do the following steps:
1. Connect to the MySQL Database, you get a MySQLConnection object.
2. Instantiate a MySQLCursor object from the the MySQLConnection object.
3. Use the cursor to execute a query by calling its execute() method.
4. Use fetchone() , fetchmany() or fetchall() method to fetch data from the result set.
5. Close the cursor as well as the database connection by calling the close() method of the corresponding object.
6. We will show you how to use fetchone() , fetchmany() , and fetchall() methods in more detail in the following sections.
Example :
dbconfig = read_db_config()
conn = MySQLConnection(**dbconfig)