interface with python
interface with python
interface with python
# CREATE DATABASE
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456")
mycor = mydb.cursor()
mycon.execute("CREATE DATABSE Pathwalla")
# SHOW DATABASE
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456")
mycor = mydb.cursor()
mycon.execute("SHOW DATABSES")
for i in mycon:
print (i)
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
mycon.execute("CREATE TABLE student (Name char (25), roll int(10), class int(10))")
mydb.commit()
mydb.close()
# SHOW TABLE
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
mycon.execute("SHOW TABLES")
for i in mycon:
print (i)
# DESCRIBE TABLE
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
mycon.execute("DESC student")
data = mycon.fetchall()
for i in data:
print (i)
# SELECT QUERY
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
mycon.execute("SELECT * FROM student")
data = mycon.fetchall()
for i in data:
print (i)
# WHERE CLAUSE
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
mycon.execute("SELECT * FROM student")
# DYNAMIC INSERTION
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
mycon.execute("INSERT INTO student VALUES ('{}', '{}', '{}',)".format (name, roll, class))
mydb.commit()
mydb.close()
# UPDATE COMMAND
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
# DELETE COMMAND
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
# DROP COMMAND
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
# ALTER COMMAND
import mysql.connector as my
mydb = my.connect(host = "localhost", user = "root", password = "123456", database = "Pathwalla")
mycor = mydb.cursor()
Answer = The database is a collection of organized information that can easily be used, managed,
update, and they are classified according to their organizational approach.
Answer = Fetching rows or columns from result sets in Python. The fetch functions in the ibm_db API
can iterate through the result set. If your result set includes columns that contain large data (such as
BLOB or CLOB data), you can retrieve the data on a column-by-column basis to avoid large memory
usage.
Answer =
# query
sql = "CREATE TABLE STUDENT (NAME char(30) NOT NULL, CLASS char(5), AGE int, GENDER char(8),
MARKS int)"
# execute query
cursor.execute(sql)
conn.commit()
# close connection
conn.close()
Answer =
Q7. Which method is used to retrieve all rows and single row?
Answer =
import mysql.connector
for x in mycursor.fetchall() :
print(x)
Thankyou!!!!!
For Solution of ‘Sumita Arora’ visit on Path Walla
For ‘Sumita Arora Type C’ solution (Programing Question) Visit our
YouTube Channel Portal Express