ColdFusion-将阿拉伯/波斯字符插入mysql [英] ColdFusion - Inserting arabic/persian characters to mysql

查看:83
本文介绍了ColdFusion-将阿拉伯/波斯字符插入mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将数据插入mysql数据库:

I insert my data into mysql db with this code:

<cfprocessingdirective pageEncoding="utf-8">     
<cfset setEncoding("URL", "utf-8")>
<cfset setEncoding("Form", "utf-8")> 
<cfcontent type="text/html; charset=utf-8">

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body> 

<cfparam name="postTextBox" default="" type="String">

<cfoutput>
    <form action="index.cfm" method="POST" name="form">
        <input name="postTextBox" type="text"/>
        <input name="" type="submit" value="Submit" />
    </form>
</cfoutput> 

<cfquery name="myQuery" datasource="hello">
    insert into ad (name)  
    values(N<cfqueryparam value=#postTextBox# cfsqltype="cf_sql_varchar">)
</cfquery>

</body> 
</html>

问题是当我插入存储在数据库中的阿拉伯语或波斯语字符时,例如"?????"但是英文字符没有问题. 我使用ColdFusion 10和mysql.

The problem is when I insert arabic or persian characters that's store in database something like "?????" but there is no problem with english characters. I use ColdFusion 10 and mysql.

致谢

推荐答案

(来自评论...)

检查列或表的字符集.确保它支持unicode字符.例如,UTF-8:

Check the charset of your column or table. Make sure it supports unicode characters. For example, UTF-8:

CREATE TABLE ( name varchar(500) CHARSET UTF8, ....)

此外,不要使用 N'literal' 语法,您也可以使用新的cfsqltype cf_sql_nvarchar.经过这些更改,它应该可以正常工作.

Also, instead of using N'literal' syntax, you may as well use the new cfsqltype cf_sql_nvarchar. With those changes, it should work fine.

    INSERT INTO ad ( name )  
    VALUES 
    (
       <!--- always scope variables ---> 
       <cfqueryparam value="#FORM.postTextBox#" cfsqltype="cf_sql_nvarchar">
    )

旁注-与您的问题无关,但cfprocessingdirective在这里无效.当您需要在CF脚本中嵌入或硬编码Unicode字符时使用它.因为您没有这样做,所以您不需要它.

Side note - Nothing to do with your question, but cfprocessingdirective has no effect here. It is used when you need to embed, or hard code, Unicode characters within a CF script. Since you are not doing that, you do not need it.

这篇关于ColdFusion-将阿拉伯/波斯字符插入mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆