Skip to content

Commit b1fa675

Browse files
authored
Using python and mysql to insert data in DB
1 parent 1db5583 commit b1fa675

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: mysql-python.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import mysql.connector
2+
import pyautogui
3+
4+
mypasswd=pyautogui.prompt('Enter your mysql password')
5+
mydb=mysql.connector.connect(host='localhost', user='root', password=mypasswd)
6+
cur=mydb.cursor()
7+
cur.execute('create database if not exists rdm123')
8+
9+
mydb1=mysql.connector.connect(host='localhost',
10+
user='root',
11+
password=mypasswd,
12+
database='rdm123')
13+
cur1=mydb1.cursor()
14+
cur1.execute('create table if not exists abc(number int(2) primary key not null auto_increment, name varchar(20), gender varchar(1))')
15+
16+
name=pyautogui.prompt('Enter Name')
17+
gender=pyautogui.prompt('Enter Gender')
18+
19+
print(name)
20+
21+
if name!=None or gender!=None:
22+
data1=(name,gender)
23+
cur1.execute('insert into abc(name , gender) values (%s,%s)',data1)
24+
mydb1.commit()
25+
pyautogui.alert('Data Filled Successfully.')
26+
else:
27+
pyautogui.alert('Data Filling Cancelled')
28+
29+
show=pyautogui.confirm(text='Would you like to show the databases?', buttons=['Yes','No'])
30+
31+
if show == 'Yes':
32+
cur1.execute('select * from abc')
33+
shwd=cur1.fetchall()
34+
pyautogui.alert(shwd)
35+
print('SUCCED!')
36+
else:
37+
print('NOT SUCCED!')

0 commit comments

Comments
 (0)