What to do to save all types of user input characters in a MySQL database?

I am creating a database web application using PHP and MySQL. I want it to be able to store any user input characters, both English and non-English, such as Arabic or Japanese, at the same time.

What should I do for this?

+3
source share
3 answers

You need to use Unicode. Read the MySQL manual section in Unicode and Joel Spolsky Absolute Minimum Every Software Developer Absolutely, should be positive about Unicode and character sets (no excuses!) .

, () / utf8. HTML/PHP UTF-8. <head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Content-Type:, Apache/PHP.

, . , Internet Explorer UTF-8, Rails 3 .

+2

MySQL UTF8:

CREATE DATABASE xx [...] DEFAULT CHARACTER SET 'utf8' DEFAULT COLLATE utf8_general_ci

PHP :

SET NAMES 'utf8'

, MySQL my.ini, :

skip-character-set-client-handshake
collation_server=utf8_unicode_ci
character_set_server=utf8

( , php.ini, MySQL ini)


PHP, : , mbstring, regexp mb_ *.

, , UTF8, . Eclipse/PDT , ( → → ).


, : . , p { direction: rtl; } CSS, , , () . , .

+2

, SQL-. , . / . , , , .

, , "" , , . , , PHPBB2, WordPress, Wiki ..

, , .

If you use PHP, the mysql_real_escape_string () function looks good: http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php Otherwise use somethign.

+1
source

Source: https://habr.com/ru/post/1758617/


All Articles