SQLite is an embedded database, and its database is a file. Python has built-in SQLite3, so using SQLite in Python does not require anything to be installed and used directly.
Operation relational database, first need to connect to the database, a database connection is called connection;
After connecting to the database, you need to open the cursor, called the cursor, execute the SQL statement through the cursor, and then get the execution result.
Python defines a set of API interfaces for manipulating databases, and any database to be connected to Python requires only a Python-compliant database driver.
Since SQLite's drivers are built into the Python standard library, we can directly manipulate the SQLite database.
Example code:
import sqlite3
conn = sqlite3.connect(‘test.db‘)
cursor = conn.cursor()
cursor.execute(‘select * from user‘)
values = cursor.fetchall() for value in values: print(value)
cursor.close()
conn.close()
Example:
Cursor.execute ('select * from user where id =%s', ('1',)) / /MySQL INSERT statement
Cursor.execute ('select * from user where id=? ', ('1',)) //SQLite INSERT statement
Python using the SQLite example