Friday, October 7, 2022

connecting python with phpmyadmin database for performming SQL operations for data engineering

# install first pip install pymysql

import pymysql

 

connection = pymysql.connect(host="hostname", user="username", passwd="password", database="db_name")

cursor = connection.cursor()


# for insert

insertsql="insert into emp(id,name) values(1,'ashraf')"

cursor.execute(insertsql)

# for update

updatesql="update emp set name='new_name' where id=1"

cursor.execute(updatesql)

# for delete 

deletesql="delete from emp where id=1"

cursor.execute(deletesql)



 # for display

selectsql="select * from emp"


cursor.execute(selectsql)

records=cursor.fetchall()

for x in records:

  print(x[2])

connection.close


Follow 👉https://lnkd.in/dDYk_vQs 👈 for awesome stuff

YouTube channel : https://youtu.be/RJdXBT7f2U8


No comments:

Post a Comment