โดย teenproza7 » 16/05/2019 4:14 pm
tatiya เขียน:ขอดู code เต็มๆครับ
โค้ด: เลือกทั้งหมด
#-*- coding=utf-8 -*-
import psycopg2 as n
try:
con = n.connect(host='localhost', user='postgres', password='', port='5432',database='testDB')
cur = con.cursor()
sql = """ insert into test_python (name_first, name_last, favorite_color ) value ('ชื่อจริง','นามสกุล','สีดำ') """
sql = sql.encode('utf-8')
try:
cur.execute(sql)
con.commit()
print('เพิ่มข้อมูล เรียบร้อยแล้ว')
except:
con.rollback()
print('เพิ่มข้อมูล ผิดพลาด')
except n.DatabaseError:
print ('Error %s' % n.DatabaseError)
if con:
con.close()
นี่ครับ
[quote="tatiya"]ขอดู code เต็มๆครับ[/quote]
[code]
#-*- coding=utf-8 -*-
import psycopg2 as n
try:
con = n.connect(host='localhost', user='postgres', password='', port='5432',database='testDB')
cur = con.cursor()
sql = """ insert into test_python (name_first, name_last, favorite_color ) value ('ชื่อจริง','นามสกุล','สีดำ') """
sql = sql.encode('utf-8')
try:
cur.execute(sql)
con.commit()
print('เพิ่มข้อมูล เรียบร้อยแล้ว')
except:
con.rollback()
print('เพิ่มข้อมูล ผิดพลาด')
except n.DatabaseError:
print ('Error %s' % n.DatabaseError)
if con:
con.close()
[/code]
นี่ครับ