I am facing problem with mysql database. I cant save arabic text into the mysql data even i change the collation to cp1256_general_ci and tried other collation. I cant get much help from search.
Anyone who can help me out please help
I have change collation at database level as well as colum level to cp1256_general_ci for some fields.
Please suggestion how should i set this as i am NEW PHP and MySQL
I also write simple INSERT statement to insert input data in mysql do i have to take any case while inserting data into mysql if it is in arabic
The short answer is: Use UTF-8 everywhere. "Everywhere" means
In all forms that are used to store data in your database
The database connection
The database tables and columns
In all pages that output data from the database.
if you have existing CP-1256 data (or incoming data in that character set that you can't change) you can use iconv() to convert it into UTF-8.
Note that if using UTF-8, you need to make sure you use multibyte-safe string functions. This is often already the case because standard function like strlen() get mapped to mb_strlen(). To find out whether this is the case on your server, see the manual entry on the issue.
Related
I have a confusing problem with php and css.
I created a database in phpmyadmin. All fields collation is utf8_general_ci. Also my table and database use the same collation as the fields. I tried every way to store data in database like using VALUES (N'content').
the most confusing problem is when I insert data using php my admin it shows at the webpage with question marks. When I store with PHP with the same SQL code it shows fine at the webpage but in the database strings shows like this:
تست Ùارسی
I really tried everything, can anyone help me through this problem?
utf8_general_ci isn't a character set, it's a collation. The collation determines how MySQL will decide how to order things when you ask it to sort alphabetically, it doesn't set the actual charset. Look at the table and the database character set, it should be UTF8 or UTF8MB4. If it's not then you've got a character set mismatch.
Please any one help me how to avoid these kind of characters â„¢ store into mysql table in php.
Thanks
To avoid these characters you should run on the active MySQL connection the query SET NAMES utf8 and also change the Charsets of the column to one that handles the characters correctly.
More Info https://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html.
Also be aware that that the text might be correctly stored and the problem might appear when you are displaying the page. If so you should add the charset meta tag as described here http://www.w3schools.com/TAgs/att_meta_charset.asp
Storing some values in a mysql database, the input is being sanitized with mysql_real_escape_string($value) and it displays fine. However while performing a direct query on the database, I'm seeing characters like †on each text field that has been edited using this form. How does that happen? It doesn't show when I display values on webpages but how can I prevent these characters from appearing at all?
I looked at this question: Strange characters in mysql dbase which seemed to have some advice on setting character names on the input, but how can I fix this for once and for all? I believe the person who's updating these values is copying and pasting directly from Microsoft Word, so I'm sure it has something to do with the "smart quotes" and other such fancy formatting that MS Word likes to use.
As the answer you linked shows, it comes from PHP which connects to mysql with latin1 encoding by default. So the datas are not correctly inserted in database.
Another problem is that if you query back the data in php, you get correct data as they are "decoded" the same way they are encoded. But if you perform direct query in database (say, with mysql client on console), data seem broken.
That's why the answer is to query "SET NAMES UTF8" before anything else.
You may parameter the mysql server to force utf8 on any connection. I do not see any other solution.
I know oracle database have two character set :
NLS_NCHAR_CHARACTERSET and NLS_CHARACTERSET.
I have set them as:
NLS_CHARACTERSET WE8MSWIN1252
NLS_NCHAR_CHARACTERSET UTF8
when I create the database.
Also I create my table use NVARCHAR not VARCHAR,so it is supposed to be saved use UTF8 :
ID NUMBER
EMAIL NVARCHAR2(255)
USER_NAME NVARCHAR2(255)
POST_AT DATE
CONTENTS NVARCHAR2(255)
However I can not get the right outputs. When I insert rows containing japanese characters, it just give out like "???" when I check it at terminal.
I don't know why it is not working. Does any one know a method to solve this problem?
Also, if I don't care how it is saved in database, just want to get the right output after taking out from database, is there any method to decode it correctly? (I have tried several method to convert encoding but not working)
I use PHP's OCI8 to access the database.
the version of oracle database is oracle 11gR2 for linux.x64
If all else fails, you can http://php.net/manual/en/function.base64-encode.php the string before inserting and decode after fetching. Worst case.
Thanks for all helps.
I cannot resolve this problem after all without recreate the database and reset the character set...
one thing I learned is that one MUST pay attention to the initial setting when creating a oracle database...
The database has a ton of entries that were not escaped because they were inputted manually when they were inserted so they look like: Don't inside of the entry, but when I try to display them they have a weird characters when I output in PHP. Before I would put anything into the database I would usually use mysqli_real_escape_string and then do the same when I go to retrieve the data, but since the data is already stored without using real_escape how do I display it properly?
The character being displayed instead of the single quotes looks like this: �
If it helps the data is stored as 'text'.
Thanks!
For future users of the same problem here's the steps:
Check your website headers to see what the encoding is
Check your mysql table columns and make sure they match.
If they don't change them to match. utf8_general in mysql and utf8 in my HTML worked for me
You will have to go back through the old mysql tables and update them so the new encoding is set properly.
New entries should work fine
When you output your results in PHP (or I guess whatever language you use), depending on if you are using any validation, you may have to use mysqli_real_escape_string or a similar function, such as stripslashes()
You'll need to read up on text encoding.
The usual solution is to make sure everything (the content-type encoding on your pages, and your mysql) are set to UTF-8
Chances are your data is Latin1 and you're displaying UTF-8 or vise versa