ColdFusion - 将阿拉伯语/波斯语字符插入 mysql

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

问题描述

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)