mirror of
https://github.com/mariadb-corporation/mariadb-connector-python.git
synced 2025-08-14 08:56:00 +00:00
Added missing example for documentation
This commit is contained in:
28
doc/examples/basic01.py
Normal file
28
doc/examples/basic01.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Import MariaDB Connector/Python module
|
||||
import mariadb
|
||||
|
||||
# Establish a connection
|
||||
connection= mariadb.connect(user="myuser", database="test", host="localhost")
|
||||
|
||||
cursor= connection.cursor()
|
||||
|
||||
# Create a database table
|
||||
cursor.execute("DROP TABLE IF EXISTS mytest")
|
||||
cursor.execute("CREATE TABLE mytest(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,"
|
||||
"first_name VARCHAR(100), last_name VARCHAR(100))")
|
||||
|
||||
|
||||
# Populate table with some data
|
||||
cursor.execute("INSERT INTO mytest(first_name, last_name) VALUES (?,?)",
|
||||
("Robert", "Redford"))
|
||||
|
||||
# retrieve data
|
||||
cursor.execute("SELECT id, first_name, last_name FROM mytest")
|
||||
|
||||
# print content
|
||||
row= cursor.fetchone()
|
||||
print(*row, sep='\t')
|
||||
|
||||
# free resources
|
||||
cursor.close()
|
||||
connection.close()
|
Reference in New Issue
Block a user