MYSQL高手来看看SQL读取中文的问题
MYSQL的高手帮我看看那错了我读取SQL失败。我是新手照猫画虎的改的插件。/* 本插件由 AMXX-Studio 中文版自动生成*//* UTF-8 func by www.DT-Club.net */
new const PLUGINNAME[] = "中文ID"
new const VERSION[] = "2.1"
new const AUTHORS[] = "poohoo @ 老友记"
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <dbi>
new g_RetryOnce
new g_SetName
new g_SetAllow
new g_host
new g_user
new g_pass
new g_dbname
new g_tabname
new Sql:g_dbc
new Result:result
public plugin_init()
{
register_plugin(PLUGINNAME, VERSION, AUTHORS)
register_cvar("amx_sql_host", "127.0.0.1")
register_cvar("amx_sql_user", "root")
register_cvar("amx_sql_pass", "123456")
register_cvar("amx_sql_db", "discuz")
register_cvar("amx_sql_table", "cdb_memberfields")
new configsDir
get_configsdir(configsDir, 63)
server_cmd("exec %s/sql.cfg", configsDir)
server_exec()
return PLUGIN_CONTINUE
}
public plugin_cfg()
{
get_cvar_string("amx_sql_host",g_host,32)
get_cvar_string("amx_sql_user",g_user,32)
get_cvar_string("amx_sql_pass",g_pass,32)
get_cvar_string("amx_sql_db",g_dbname,32)
get_cvar_string("amx_sql_table",g_tabname,32)
return PLUGIN_CONTINUE
}
// 名字更改消息
public client_infochanged(id)
{
if (!is_user_connected(id))
return PLUGIN_CONTINUE
// 更换限制标记
if (!g_SetAllow)
{
new oldname, newname
get_user_name(id, oldname, 31)
get_user_info(id, "name", newname, 31)
if (strcmp(newname, oldname)==0)
return PLUGIN_CONTINUE
// 兼容 sXe 改名
if (equal(newname, "", 10))
{
replace(oldname, 31, " ", "")
formatex(newname, 31, " %s", oldname)
ig_setname(id, newname)
}
else
ig_setname(id, oldname)
return PLUGIN_CONTINUE
}
g_SetAllow = 0
ig_setname(id, g_SetName)
return PLUGIN_CONTINUE
}
// 重名检查
one_name(id, name[], len)
{
new sample, s
copy(sample, 31, name)
for (new i=0; i<33; i++)
{if(s>0)formatex(sample, 31, "(%d)%s", s, name)
if (!is_name_inuse(id, sample))
break
s++
}
copy(name, len, sample)
}
is_name_inuse(id, const sample[])
{
new name
for (new i=1; i<=get_maxplayers(); i++)
{
if (!is_user_connected(i)) continue
if (id==i) continue
get_user_name(i, name, 31)
if (strcmp(name, sample)==0)
return 1
}
return 0
}
// 设置 id 需要的名字
public set_name(id, const newname[])
{
if (strlen(newname)<1)
return
g_SetAllow = 1
copy(g_SetName, 31, newname)
one_name(id, g_SetName, 31)
set_user_info(id, "name", g_SetName)
}
public client_connect(id)
{
remove_task(id)
g_SetAllow = 0
// 强制重新连接一次,以解决因为换中文ID后,换图会出现权限认证问题
if (!g_RetryOnce)
{
g_RetryOnce = 1
client_cmd(id, "retry")
}
}
public client_putinserver(id)
{
// 延时足够的时间,等待 admin 权限认证插件完成权限设置后,再执行更换名字
set_task(random_float(3.0,10.0), "get_name_from_file", id)
}
// 从文件里检查是否有对应的中文ID
public get_name_from_file(id)
{
if (!is_user_connected(id))
return
new name
get_user_name(id, name, 31)
new set = 0
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname)
if (g_dbc == SQL_FAILED)
log_amx("SQL Connection Failed")
else
{
result = dbi_query(g_dbc,"set name utf8;")
result = dbi_query(g_dbc,"select * from `%s` where auth = '%s'", g_tabname, name)
if (result == RESULT_FAILED)
{
log_amx("Sorry,No DataBase or Table")
}
else if(result == RESULT_NONE)
{
new tmpName, tmpNameCN
dbi_result(result, "auth", tmpName, 31)
dbi_result(result, "cnname",tmpNameCN,31)
dbi_free_result(result)
parse(tmpName,sizeof(tmpName)-1, tmpNameCN,sizeof(tmpNameCN)-1)
trim(tmpName)
trim(tmpNameCN)
if (strcmp(name, tmpName)==0)
{
copy(name, 31, tmpNameCN)
set = 1
}
}
dbi_close(g_dbc)
// 完成后,设置新的名字
if (set)
set_name(id, name)
}
}
SET NAMES 'UTF8' 本帖最后由 sakulekingz 于 2009-4-26 18:56 编辑
result = dbi_query(g_dbc,"set names 'utf8'") 哦 谢谢 我用你的去试试 很好用啊、。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 加在那里呢? 加在那里呢?
shuyeshuye 发表于 2011-8-27 11:11 http://www.dt-club.net/forum/images/common/back.gif
哈哈,阳光F管理员
页:
[1]