File tree 8 files changed +132
-0
lines changed
8 files changed +132
-0
lines changed Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456"
7
+ )
8
+
9
+ if db .is_connected ():
10
+ print ("Database Connected" )
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456"
7
+ )
8
+
9
+ cursor = db .cursor ()
10
+ cursor .execute ("CREATE DATABASE employee_data" )
11
+
12
+ print ("Database Created Successful !!!" )
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456" ,
7
+ database = "employee_data" ,
8
+ )
9
+
10
+ cursor = db .cursor ()
11
+ sql = """CREATE TABLE customers (
12
+ customer_id INT AUTO_INCREMENT PRIMARY KEY,
13
+ name VARCHAR(255),
14
+ address Varchar(255)
15
+ )
16
+ """
17
+ cursor .execute (sql )
18
+
19
+ print ("Table Created Successful !!!" )
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456" ,
7
+ database = "employee_data" ,
8
+ )
9
+
10
+ cursor = db .cursor ()
11
+ sql = "DELETE FROM customers WHERE customer_id=%s"
12
+ val = (4 , )
13
+ cursor .execute (sql , val )
14
+
15
+ db .commit ()
16
+
17
+ print ("{} data deleted" .format (cursor .rowcount ))
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456" ,
7
+ database = "employee_data" ,
8
+ )
9
+
10
+ cursor = db .cursor ()
11
+ sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
12
+ values = [
13
+ ("Shakib" , "Magura" ),
14
+ ("Tamin" , "Ctg" ),
15
+ ("Taskin" , "Dhaka" ),
16
+ ("Mushfiq" , "Rajshahi" )
17
+ ]
18
+
19
+ for val in values :
20
+ cursor .execute (sql , val )
21
+
22
+ db .commit ()
23
+
24
+ print ("{} data added" .format (cursor .rowcount ))
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456" ,
7
+ database = "employee_data" ,
8
+ )
9
+
10
+ cursor = db .cursor ()
11
+ sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
12
+ val = ("Mr Taif" , "Dhaka" )
13
+ cursor .execute (sql , val )
14
+
15
+ db .commit ()
16
+
17
+ print ("{} data added" .format (cursor .rowcount ))
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456" ,
7
+ database = "employee_data" ,
8
+ )
9
+
10
+ cursor = db .cursor ()
11
+ sql = "SELECT * FROM customers"
12
+ cursor .execute (sql )
13
+
14
+ results = cursor .fetchall ()
15
+
16
+ for data in results :
17
+ print (data )
Original file line number Diff line number Diff line change
1
+ import mysql .connector
2
+
3
+ db = mysql .connector .connect (
4
+ host = "127.0.0.1" ,
5
+ user = "root" ,
6
+ password = "123456" ,
7
+ database = "employee_data" ,
8
+ )
9
+
10
+ cursor = db .cursor ()
11
+ sql = "SELECT * FROM customers"
12
+ cursor .execute (sql )
13
+
14
+ result = cursor .fetchone ()
15
+
16
+ print (result )
You can’t perform that action at this time.
0 commit comments