Python 3 Veri tabanından kayıt okuma
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 27 28 |
import pymysql.cursors # Veritabanı bağlantı cümlesi connection = pymysql.connect(host='localhost', user='root', password='', db='ogrenciler', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) try: with connection.cursor() as cursor: # tek satır okuma sql = "SELECT `id`, `firstname`,`lastname` FROM `users`" cursor.execute(sql) for row in cursor.fetchall(): #tüm satırları okuma firstname = str(row["firstname"]) lastname = str(row["lastname"]) #ekrana yazdırma print("İsim : " + firstname) print("Soyisim : " + lastname) finally: connection.close() |
Add Comment