การติดต่อ/เชื่อมต่อกับ Database MySQL ด้วย Python
การติดต่อ/เชื่อมต่อกับ Database MySQL ด้วย Python
import library
import mysql.connector
กำหนดทางเข้าของ mysql ของเรา
mydb = mysql.connector.connect(
host=””,
user=””,
password=”",
database=””
)
insert ข้อมูลลง mysql
mycursor = mydb.cursor()
sql = “INSERT INTO lp (lp_vdo, lp_p, lp_date, lp_speed,ip_char) VALUES (%s,%s,%s,%s,%s)” # %s ต้องมีจำนวนเท่ากับจำนวน field
val = (lp_vdo, lp_p,text_day+text_time, lp_speed,ip_char) #ตัวแปรในการ insert
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, “record inserted.”)
หมายเหตุท้าย:
หากคุณชอบบทความนี้อย่าลืมคลิก❤ด้านล่างเพื่อแนะนำและถ้าคุณมีคำถามใด ๆ แสดงความคิดเห็นและฉันจะพยายามอย่างดีที่สุดที่จะตอบ คุณสามารถติดตามฉันบน
facebook page (https://www.facebook.com/nextsoftwarehousethailand/)
website : www.nextsoftwarethailand.com
และสามารถส่งอีเมลถึงฉัน