Advertisement
afrizalwahyuadi66

mysql-insert.py

Dec 11th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import mysql.connector
  2. db = mysql.connector.connect(host="localhost",
  3.                              user="root",
  4.                              password="", database="db11230070")
  5.  
  6. while(True):
  7.     npm = input("NPM Mahasiswa  :")
  8.     nama = input("Nama Mahasiswa    :").title()
  9.     jk = input("Jenis Kelamin (P/L) :").upper()
  10.     prodi = input("Program Studi (SI/IF)    :").upper()
  11.     val = (npm, nama, jk, prodi)
  12.     cursor = db.cursor()
  13.     sql = "INSERT INTO tblmahasiswa values (null, %s, %s, %s, %s)"
  14.     cursor.execute(sql,val)
  15.     db.commit()
  16.     print("{} record berhasil disimpan". format(cursor.rowcount))
  17.    
  18.     ulang=input("Ulangi input data? (y/t)").lower()
  19.     if(ulang!="y"):
  20.         break
  21.  
Tags: mysql-python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement