Insert a Persian Text in MySQL Table

Insert a persian text in mysql table

make sure the collation is utf8. collation persiab case insensitive may not work properly as the input char code may not be in range of persian charachters. unicode 8 will work. change the collation to utf8_general

Storing persian\Arabic text in mysql database

It seems you are using php to populate $data. So you have to set charset as UTF8 (i.e. SET NAMES 'utf-8';). For example if you were using mysqli, your code would be like this:

<?php
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
mysqli_set_charset($conn,"utf8");

Or use this answer if you were using PDO or this one for deprecated mysql. Moreover, do not forget to use utf8-persian-ci collection.

In your html if you have a form, set the accept-charset as UTF-8:

<form action="" accept-charset="UTF-8">

Save Persian Text With Emoji in MySQL Database

درود they way we do that is by using a utf8mb4_persian_ci

CREATE TABLE `users` (

) DEFAULT CHARSET = utf8mb4_persian_ci

This is how we would go about doing that.
Persian Text will be saved using utf8mb4 it also Supports Emoji's and Much Much more !

Persian character's issue in mysql database

solved:

in connection

<?php
$dbLink = mysql_connect($argHost, $argUsername, $argPassword);
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
mysql_select_db($argDB, $dbLink);
mysql_query("set names 'utf8'",$dbLink);
?>

source:
PHP mysql charset utf8 problems

ColdFusion - Inserting arabic/persian characters to mysql

(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.

Save Persian string into mysql database with python

Please note that this is the first time I am trying to read Arabic / Persian characters, so the following information might not be correct (I could have made a mistake when comparing my test output with the Persian string you have shown in your question). Furthermore, I never have heard of flask so far.

Having said this:

1587 1604 1575 1605 is the sequence of code points which represents the Persian string you have shown in Unicode. Now, in HTML, Unicode code points (in decimal) can be encoded as entities in the form &#xxxx;. So the string سلام is one of the allowed forms of representation of that string in HTML.

Given that, there could be two possible reasons for the misbehavior:

1) request.json['Message'] already contains / returns HTML (and not natural text) and (for some reason I don't know) contains / returns the string in question in HTML-entity encoded form. So this is the first thing you should check.

2) cursor_.execute(...) somehow encodes the string into HTML and thereby (for some reason I don't know) encodes your string in question into HTML-entity encoded form. Perhaps you have told your database driver to encode non-ASCII characters in message_ as HTML entities?

For further analysis, you could check what happens in a test case where request.json['Message'] contains / returns only ASCII characters.

If ASCII characters are written into the database as HTML entities as well, there must be a basic problem which causes all characters without exception to be encoded into HTML entities.

Otherwise, you eventually have not told your database, your database drivers or your file system drivers which encoding to use. In such cases, ASCII characters are often treated correctly, whereas weird things happen to non-ASCII characters. Automatically encoding non-ASCII characters to HTML entities during file IO or database operations would be very unusual, though. But as mentioned above, I don't know flask ...

Please consult the MySQL manual to see how to set the character encoding for databases, tables, columns and connections, your database driver documentation to see which other things you must do to get this encoding to be handled correctly, and your interpreter's and its libraries' manuals to see how to correctly set that encoding for file IO (CGI works via STDIN / STDOUT).

You make your life a lot easier if the database character encodings and the file IO encoding are all the same. Personally, I always use UTF-8.

A final note: Since I don't know anything about flask, I don't know what # -*- coding: utf-8 -*- is supposed to do. But chances are that this only tells the interpreter how the script itself is encoded, but not which encoding to use for input / output / database operations.



Related Topics



Leave a reply



Submit