ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
Posted: 16/05/2019 4:08 pm
ผมไม่สามารถสร้างข้อมูลลงในตารางได้ครับมันขึ้น Error แบบนี้

ขอวิธีแก้ด้วยครับ
ขอวิธีแก้ด้วยครับ
เว็บบอร์ด PHP ใช้งานจริงใน ธุรกิจ ด้วยเทคโนโลยี Ajax HTML5 Framework SQL CMS CRM ERP Hosting
https://www.mindphp.com/forums/
tatiya wrote:ขอดู code เต็มๆครับ
Code: Select all
#-*- 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: Select all
a = "ทดสอบ"
b = a.encode('utf-8')
Code: Select all
# -*- coding: utf-8 -*-
Code: Select all
#-*- coding=utf-8 -*-