将阿拉伯语unicode转换为字符串stroe在python中的mysql并读取lua中的数据
问题描述:
我有一个var unicode来自python中的scrapy,我已经将这个存储在mysql中。我尝试了所有的网络方式来编码为utf-8
,我的Unicode字符转换成字符串以这种方式将阿拉伯语unicode转换为字符串stroe在python中的mysql并读取lua中的数据
unicode.encode('utf-8')
并存储在Python文件这方面,DB
db = MySQLdb.connect(host="",
user="",
passwd="",
db="",
cursorclass=MySQLdb.cursors.DictCursor,
charset='utf8',
init_command='SET NAMES UTF8'
)
然后我读数据从这个代码在lua中的mysql
local env = assert (luasql.mysql())
local con = assert (env:connect("","",""))
local cursor,errorString = assert (con:execute("SELECT `id`,`arabic_name`,`arabic_lastname` FROM `user_info`"))
local row = cursor:fetch ({}, "a")
当我在while循环中打印结果的行。它是返回我????
字符串的类型 我在Python中试过这种方式,并再次返回我????
, 但在phpmyadmin我已经看到正确类型的字符串的列。 我猜lua和python中的mysql库不能返回正确类型的阿拉伯字符串
有人知道我怎么解决这个问题和问题在哪里?存储数据或读取数据!
答
您是否尝试过SET NAMES cp1256
以声明客户端字节被编码为CP1256?然后
表的列可能是要么utf8
或cp1256
和转码会被MySQL中INSERT
和SELECT
来完成。
你想在python或lua中做到这一点? – gommb
我想在lua.python中读取记录以供在此项目中阅读并且可以使用lua进行阅读。我设置mysql表和集合到utf8_general_ci –
可能重复[从utas8格式的luasql读取数据](https://*.com/questions/46966247/read-data-from-luasql-with-utf8-format) – tarleb