+ 3

SQL and Python combination

Can you please explain how SQL can be used with python in the projects? What primary knowledge should we have in this regard??

4th May 2020, 12:27 AM
MD. Jashim Uddin
MD. Jashim Uddin - avatar
2 Answers
+ 4
You have to install mysql.connector for that and then import the package as "import mysql. Connector as sq" on your python IDLE. Then open a connection to the database as "cob=sq.connect (host=host name, user=username,password =password of mysql,charset= utf-8)" Then create a cursor instance as "cur=cob.cursor()" after which you have to execute the query as "cur.execute(<SQL query string you want to run>)". Then, you can extract the data from mysql table using fetchall() method. Note: All these steps must be executed in python idle.... Good luck bro...
4th May 2020, 12:53 AM
Ayush Dwivedi
Ayush Dwivedi - avatar
+ 1
sqlite3 is a lightweight database engine and it is built into standard python (no external library needed to use it). For more advanced integration, you can look at sqlalchemy ORM (object relational mapper) that provodes an abstraction over various types of databases. https://www.sqlalchemy.org/ https://code.sololearn.com/csZ5bjiWfdCR/?ref=app
4th May 2020, 8:05 AM
Tibor Santa
Tibor Santa - avatar