I insert my data into mysql db with this code:
(From comments ...)
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, ....)
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">
)
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.
The issue of having "????" marks instead of Arabic Characters could be two issues; With the assumption that you are using MySQL 5, with ColdFusion 10 or 11:
First Issue: It could be that you have not setup the MySQL database to UTF-8, in order to convert all your DB to UTF-8, use the following commands on MySQL:
Use the ALTER DATABASE
and ALTER TABLE
commands.
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Second Issue: The ColdFusion DataSource has not been setup properly and it will need two more additional strings to be added using the ColdFusion Data Source
options.
Go to the ColdFusion Administrator, and open the Data Source
page and click on the data Source that you have setup already.
Data & Services > Datasources > MySQL 5
Click the Data Source Name
and click Show Advanced Settings
, on the Connection String
feild add the following two sting values.
useUnicode=true&characterEncoding=utf8
Once after you have saved the configuration details, the ColdFusion will start converting the data in to UTF-8
charachter set, and you will have proper Arabic or Persian characters.
Note: If you are hosting with some hosting service providers, such as my hosting company, you will have to request this to be added to the Data-source for your DB from the hosting support teams, I'm sure most of the hosting companies will have no issue in adding them to you. Also note they might have a load-balancing environment, and in this case you might some times get the '????' and some times the proper 'Arabic' characters, in this case make sure they add the above string to all their CF servers on the H/A environment (i.e. this happened to me).
Hope this helps resolve the issue.