-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql1.py
More file actions
26 lines (22 loc) · 858 Bytes
/
sql1.py
File metadata and controls
26 lines (22 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import mysql.connector
from _ctypes import buffer_info
my=mysql.connector.connect(user="root",
host="localhost",
password="root")
cursor=my.cursor(buffered=True)
cursor.execute("use user")
cursor.execute("select * from user_d")
print(cursor.fetchall())
for record in cursor.fetchall():
print("Record found",record)
#cursor.execute("CREATE table Persons (Personid int
# NOT NULL AUTO_INCREMENT, LastName varchar(255) NOT NULL,FirstName varchar(255),Age int(255),
# PRIMARY KEY (Personid))")
#insert_query="insert into Persons values(1,'Lname','Fname',34)"
insert_query="insert into Persons values(null,'Lname','Fname',34)"
cursor.execute(insert_query)
insert_query="insert into Persons values(null,%s,%s,%s)"
data=[("l","m",5),
("k","p",7)]
cursor.executemany(insert_query,data)
my.commit()