· 7 years ago · Nov 12, 2018, 03:06 PM
1import sqlite3
2
3class db_islem:
4 def __init__(self):
5 self.baglanti = sqlite3.connect('okul_veri.db')
6 if(self.baglanti):
7 print('Baglanti Başarılı!')
8 else:
9 print('Bağlantı Başarısız!')
10
11 self.db = self.baglanti.cursor()
12
13 def show_db(self):
14 oku = self.db.execute('SELECT * FROM ogrenciler')
15 d= oku.fetchall()
16 print(d)
17
18 def create_table(self):
19 self.db.execute('''
20 CREATE TABLE IF NOT EXISTS ogrenciler(
21 ogrenci_no INTEGER PRIMARY KEY,
22 adi varchar,
23 soyadi varchar
24 )
25''')
26
27 def update_data(self):
28 pass
29
30 def insert_data(self, no, ad, soyad):
31 o1 = """INSERT INTO ogrenciler (ogrenci_no,adi,soyadi) VALUES ({},"{}","{}")""".format(no, ad, soyad)
32 self.db.execute(o1)
33 self.baglanti.commit()
34
35 def delete_data(self):
36 pass
37
38 def search(self):
39 pass
40 def close(self):
41 self.baglanti.close()
42
43f = db_islem()
44f.create_table()
45f.insert_data(57, "cihat","47")
46
47
48f.show_db()
49f.close()