Narisa.com: Python+mysql+ภาษาไทย - Narisa.com

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Python+mysql+ภาษาไทย Rate Topic: -----

#1 User is offline   sayam 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 13-December 03

Posted 03 January 2007 - 11:27 AM

Python+mysql+ภาษาไทย เขียนอย่างไงครับผม insert ได้แต่ภาษาอังกฤษ
จะทำ webboard รบกวนด้วยครับ จะทำงานส่งอาจารย์
0

#2 User is offline   up1 

  • Topgun
  • View blog
  • Group: Topgun
  • Posts: 2483
  • Joined: 04-March 04

Posted 03 January 2007 - 11:30 AM

View Postsayam, on Jan 3 2007, 11:27 AM, said:

Python+mysql+ภาษาไทย เขียนอย่างไงครับผม insert ได้แต่ภาษาอังกฤษ
จะทำ webboard รบกวนด้วยครับ จะทำงานส่งอาจารย์


ตอนนี้ develop ในแต่ละส่วนไปอย่างไรบ้าง ลองเอามา post เพื่อเป็นข้อมูลในการแก้ไขปัญหาครับ หน่อยครับ
0

#3 User is offline   sayam 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 13-December 03

Posted 03 January 2007 - 11:44 AM

code ครับ

#!/dev/python24/python
# -*- coding: cp874 -*-
import MySQLdb,cgi
conn = MySQLdb.connect("localhost","root","","wb")
cursor = conn.cursor()
sql = "insert into question(q_name,q_email,q_title,q_detail) values('สยาม','dsafasf','sdfgsdg','sdfsdfsd')"
cursor.execute(sql)
cursor.execute(sql)
cursor.close()
conn.close()


error ครับ

Traceback (most recent call last):
File "C:/Documents and Settings/MATH/Desktop/te", line 7, in -toplevel-
cursor.execute(sql)
File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 146, in execute
query = query.encode(charset)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xca in position 75: ordinal not in range(128)
0

#4 User is offline   Patrickz 

  • Topgun
  • View blog
  • Group: Topgun
  • Posts: 2624
  • Joined: 27-May 03

Posted 03 January 2007 - 02:26 PM

MySQL version ไหนครับ?

ได้ลองค้นหาใน narisa หรือยังครับ?
0

#5 User is offline   sayam 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 24
  • Joined: 13-December 03

Posted 03 January 2007 - 07:03 PM

Mysql 3.23.58 ครับ
0

#6 User is offline   Patrickz 

  • Topgun
  • View blog
  • Group: Topgun
  • Posts: 2624
  • Joined: 27-May 03

Posted 04 January 2007 - 01:00 PM

View Postsayam, on Jan 3 2007, 07:03 PM, said:

Mysql 3.23.58 ครับ


ใช้ 4.1 ขึ้นไปครับ แล้วลองค้นหา google ด้วย mysql ภาษาไทย
0

#7 User is offline   work4best 

  • Topgun
  • View blog
  • Group: Topgun
  • Posts: 618
  • Joined: 04-May 04

Posted 05 January 2007 - 11:29 AM

View Postsayam, on Jan 3 2007, 11:44 AM, said:

code ครับ

#!/dev/python24/python
# -*- coding: cp874 -*-
import MySQLdb,cgi
conn = MySQLdb.connect("localhost","root","","wb")
cursor = conn.cursor()
sql = "insert into question(q_name,q_email,q_title,q_detail) values('สยาม','dsafasf','sdfgsdg','sdfsdfsd')"
cursor.execute(sql)
cursor.execute(sql)
cursor.close()
conn.close()


error ครับ

Traceback (most recent call last):
File "C:/Documents and Settings/MATH/Desktop/te", line 7, in -toplevel-
cursor.execute(sql)
File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py", line 146, in execute
query = query.encode(charset)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xca in position 75: ordinal not in range(128)

ผมใช้ source coding อย่างงี้ครับ
# -*- coding: UTF-8 -*-


เวลาสร้าง connection ผมมักจะสร้างอย่างงี้ครับ
MySQLdb.connect(
        user='user',
        passwd='pass',
        db='yourdb',
        use_unicode=True,
        charset='utf8')


แล้วเวลาจะ insert ให้เปลี่ยน 'สยาม' เป็น u'สยาม' นะครับ

This post has been edited by work4best: 05 January 2007 - 11:33 AM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users