2006年12月07日 星期四 11:53
#!J:/activepython # -*- coding: utf-8 -*- import MySQLdb print "ok" db=MySQLdb.Connect("localhost","root","root",db="sp9",charset="utf8") cu=db.cursor() sql="insert into test values(%s,%s,%s)" param=(5,"china","¹ú") cu.execute(sql,param) db.commit() cu.execute("select * from test") for row in cu.fetchall(): for fd in row: print fd ===========================ÎÒÔËÐÐÉÏÃæµÄ³ÌÐò,×ÜÌáʾ˵,²åÈëÊý¾ÝÌ«³¤.ÁÐΪµÚ3ÁÐ. Èç¹ûsql="""insert into test values(5,'china','Öйú')""" »¹»á³öÏÖ±àÂëÎÊÌâ?ÎÒ¶ÁÊý¾Ýµ¹ÊÇÕý³£µÄ... ºÜÓôÃÆ°¡,ÍøÉϺöིµÄÒ²²»Çå³þ,ÊÔÁ˺öà´Ê¶¼²»Ðа¡.ÄÇλ¸øÒÔ¸ø¸öÕýÈ·µÄÀý×Ó°¡? ÎÒÓõÄÊÇmysql5.0 Êý¾Ý¿âºÍ±íµÄ±àÂ붼ÊÇutf8,python2.4,MySQLdbÇý¶¯ÊǸÕϵÄ..... Èç¹ûÄܹ»Ìṩһ¸öpython+mysqlµÄ¿ªÔ´µÄÏîÄ¿²Î¿¼ÔòʵÔÚÐÒÉõ...TKS -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20061207/e033c994/attachment.html
2006年12月07日 星期四 11:58
插入之前执行一下 set names 'utf8' 试试 在 06-12-7,janux<janux at boulder.com.cn> 写道: > > #!J:/activepython > # -*- coding: utf-8 -*- > import MySQLdb > print "ok" > db=MySQLdb.Connect("localhost","root","root",db="sp9",charset="utf8") > cu=db.cursor() > sql="insert into test values(%s,%s,%s)" > param=(5,"china","国") > cu.execute(sql,param) > db.commit() > cu.execute("select * from test") > for row in cu.fetchall(): > for fd in row: > print fd > > ===========================我运行上面的程序,总提示说,插入数据太长.列为第3列. > 如果sql="""insert into test values(5,'china','中国')""" 还会出现编码问题?我读数据倒是正常的... > 很郁闷啊,网上好多讲的也不清楚,试了好多词都不行啊.那位给以给个正确的例子啊? > 我用的是mysql5.0 数据库和表的编码都是utf8,python2.4,MySQLdb驱动是刚下的..... > 如果能够提供一个python+mysql的开源的项目参考则实在幸甚...TKS > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to > python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese >
Zeuux © 2025
京ICP备05028076号