Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymysql
- connection = pymysql.connect(
- host='localhost',
- user='root',
- password='',
- db='buku',
- )
- def tampil():
- try:
- with connection.cursor() as cursor:
- sql1 = "SELECT `id_buku`, `title`, `category`, `harga` FROM buku"
- try:
- cursor.execute(sql1)
- result = cursor.fetchall()
- print("Id_buku\t Title\t\tCategory\tHarga")
- print("---------------------------------------------------------")
- for row in result:
- print(str(row[0]) + "\t" + row[1] + '\t' + row[2] + "\t\t" + str(row[3]))
- except pymysql.Error as e:
- print("Oops! Something wrong", e)
- connection.commit()
- finally:
- connection.close()
- if __name__=='__main__':
- tampil()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement