python - django1.8 MySQL中文输入乱码
巴扎黑
巴扎黑 2017-04-17 16:36:03
[Python讨论组]
(1064, "You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for 
the right syntax to use near 'a.txn_id=b.dict_id and  
(b.dict_name like '%\xe5\x86\xb2\xe6\xad\xa3' 
or b.dict_name like '%\xe9\x80\x80\xe8\xb4\xa7' at line 1")

所有的数据库都是设置成utf8了,文件也是utf8就是搞不清楚哪里错,py使用如下

   
 cursor = connection.cursor()
            cursor.execute(
                "select (select c.org_name from sys_org c where c.mid=a.mid and c.id like %s) as org_name,"+
                "a.pan,a.txn_amt,(select d.dict_name from sys_dict d where d.dict_type='sys_tran_appl' and  a.appl_id=d.dict_id) as appl_name,"+
                "b.dict_name,a.txn_date,a.txn_time "+
                "from trans a,sys_dict b"+
                "where a.txn_id=b.dict_id and  (b.dict_name like %s or b.dict_name like %s) "+
                "and and CONCAT(txn_date,' ',txn_time) between %s and %s "+
                "order by CONCAT(txn_date,' ',txn_time) desc ",
                [user.sys_org_id + "%",u'%冲正',u'%退货',min_datetime, max_datetime]
            )
            cursor.execute("SET NAMES 'utf8'; ")
            fetchall = cursor.fetchall()
巴扎黑
巴扎黑

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号