Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DanielBarnes18
GitHub Repository: DanielBarnes18/IBM-Data-Science-Professional-Certificate
Path: blob/main/07. Data Analysis with Python/Using DB-API Notes.ipynb
8090 views
Kernel: Unknown Kernel

Writing code using DB-API

The following format of code should be used when using the DB-API:

#Necessary import from dbmodule import connect #Create connection object connection = connect('databasename', 'username', 'password') #Create a cursor object cursor = connection.cursor() #Run queries cursor.execute('select * from mytable') results = cursor.fetchall() #Free resources up Cursor.close() connection.close()