fork download
  1. import mysql.connector
  2. mycon = mysql.connector.connect(
  3. host='localhost',
  4. user='root',
  5. password='password',
  6. database='School')
  7. if mycon.is_connected():
  8. print('Database connected')
  9. cursor = mycon.cursor()
  10. sql ="SELECT * FROM STUDENT WHERE Stream='Medical'"
  11. cursor.execute(sql)
  12. records = cursor.fetchall()
  13. print("Answer is:")
  14. for rec in records:
  15. print(rec)
Success #stdin #stdout 0.02s 25940KB
stdin
Standard input is empty
stdout
import mysql.connector
mycon = mysql.connector.connect(
      host='localhost',
      user='root',
      password='password', 
      database='School')
if mycon.is_connected():
   print('Database connected')
cursor = mycon.cursor()
sql ="SELECT * FROM STUDENT WHERE Stream='Medical'"
cursor.execute(sql)
records = cursor.fetchall()
print("Answer is:")
for rec in records:
print(rec)