ขอวิธีแก้ด้วยครับ
ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
Moderators: mindphp, ผู้ดูแลกระดาน
-
- PHP Super Member
- Posts: 204
- Joined: 13/05/2019 10:03 am
ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
ผมไม่สามารถสร้างข้อมูลลงในตารางได้ครับมันขึ้น Error แบบนี้

ขอวิธีแก้ด้วยครับ
ขอวิธีแก้ด้วยครับ

-
- PHP VIP Members
- Posts: 2845
- Joined: 09/07/2018 9:35 am
Re: ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
ขอดู code เต็มๆครับ
-
- PHP Super Member
- Posts: 204
- Joined: 13/05/2019 10:03 am
Re: ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
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()

-
- PHP VIP Members
- Posts: 2845
- Joined: 09/07/2018 9:35 am
Re: ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
ถ้า value ที่จะใส่เป็นภาษาไทย ให้เก็บไว้ในตัวแปร และแปลง encode ก่อน
Code: Select all
a = "ทดสอบ"
b = a.encode('utf-8')
-
- PHP VIP Members
- Posts: 19782
- Joined: 31/03/2014 10:02 am
- Contact:
Re: ไม่สามารถสร้างข้อมูลในตาราง PostgreSQL ได้ครับ
เปลี่ยนเป็น
จาก
Code: Select all
# -*- coding: utf-8 -*-
Code: Select all
#-*- coding=utf-8 -*-
Users browsing this forum: facebook.com [Crawler] and 4 guests