일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 경영
- Regex
- OOP
- JavaScript
- Laravel
- JSON
- function
- Apache
- post
- date
- string
- composer-php
- MySQL
- file-upload
- HTML
- Ajax
- variables
- Arrays
- jquery
- Linux
- php
- UTF-8
- 웹하드순위
- curl
- 전략
- 무료다운로드쿠폰
- Forms
- 웹하드추천
- Session
- Today
- Total
개발! 딱 깔끔하고 센스있게!
MySQL 및 PHP : 키릴 문자가있는 UTF-8 본문
나는 mysql 시계에 시릴치를 삽입하려고 했지만 인코딩이 문제가 있다.
필리핀 피소:
connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "UPDATE `c`.`mainp` SET `search` = 'test тест' WHERE `mainp`.`id` =1;"; if ($conn->query($sql) === TRUE) { } $conn->close(); ?>
MySQL 데이터베이스:
| id | search | | 1 | test ав |
주: php 파일은 utf-8, 데이터베이스 정렬은 utf8u generalu ci
대답
You are mixing APIs here,
mysql_*
andmysqli_*
doesn't mix. You should stick withmysqli_
(as it seems you are anyway), asmysql_*
functions are deprecated, and removed entirely in PHP7.
너의 실제 문제는 어느 곳의 문자 집합 문제이다.
여기에 몇몇 지침들이 프로그램을 위해 정확한 문자 집합을 얻을 수 있도록 도와줄 수 있습니다.
php/mysql 응용 프로그램을 개발할 수 있는 대부분의 일반 문제가 포함되어 있습니다.
- ALL attributes throughout your application must be set to UTF-8
- Save the document as UTF-8 w/o BOM (If you're using Notepad++, it's
Format
->Convert to UTF-8 w/o BOM
) -
The header in both PHP and HTML should be set to UTF-8
-
HTML (inside
-
PHP (at the top of your file, before any output):
header('Content-Type: text/html; charset=utf-8');
-
-
Upon connecting to the database, set the charset to UTF-8 for your connection-object, like this (directly after connecting)
mysqli_set_charset($conn, "utf8"); /* Procedural approach */ $conn->set_charset("utf8"); /* Object-oriented approach */
This is for
mysqli_*
, there are similar ones formysql_*
and PDO (see bottom of this answer). -
Also make sure your database and tables are set to UTF-8, you can do that like this:
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci; ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
(Any data already stored won't be converted to the proper charset, so you'll need to do this with a clean database, or update the data after doing this if there are broken characters).
- If you're using
json_encode()
, you might need to apply theJSON_UNESCAPED_UNICODE
flag, otherwise it will convert special characters to their hexadecimal equivalent.
전체 코드 파이프의 모든 내용은 uft-8 설정이 필요합니다.
그렇지 않으면 프로그램에서 끊기는 문자가 생길 수 있습니다.
이 목록 외에도 일부 함수는 지정 문자 집합에 사용할 특정 인자를 가지고 있을 수 있습니다.
설명서는 이 점을 알려드릴 것입니다.
여러 바이트 문자를 겨냥한 특수함수는 예를 들어: strToLower () 가 여러 바이트 문자의 값을 낮추지 않으므로 mb strToower () 를 사용해야 합니다.
이 실시간 시사회를 참고하십시오.
Note 1: Notice that its someplace noted as
utf-8
(with a dash), and someplace asutf8
(without it). It's important that you know when to use which, as they usually aren't interchangeable. For example, HTML and PHP wantsutf-8
, but MySQL doesn't.Note 2: In MySQL, "charset" and "collation" is not the same thing, see Difference between Encoding and collation?. Both should be set to utf-8 though; generally collation should be either
utf8_general_ci
orutf8_unicode_ci
, see UTF-8: General? Bin? Unicode?.Note 3: If you're using emojis, MySQL needs to be specified with an
utf8mb4
charset instead of the standardutf8
, both in the database and the connection. HTML and PHP will just haveUTF-8
.
mysql 및 pdo 설정 utf-8
-
PDO: This is done in the DSN of your object. Note the
charset
attribute,$pdo = new PDO("mysql:host=localhost;dbname=database;charset=utf8", "user", "pass");
-
mysql_
: This is done very similar tomysqli_*
, but it doesn't take the connection-object as the first argument.mysql_set_charset('utf8');
'개발 스크랩 메모 > PHP' 카테고리의 다른 글
Liux Fdora 에서 Apache 의 PHP 를 어떻게 사용 합 니까? (0) | 2020.12.13 |
---|---|
PHP 젝스키스 - (int) 와 FILTER VALIDATE int (0) | 2020.12.12 |
.htaccess (PHP)를 사용하여 즉시 하위 도메인 만들기 (0) | 2020.12.11 |
PHP 5에서 발신자 기능 (0) | 2020.12.11 |
PHP 에서 여러 디 렉 터 리 에 어떻게 spl autoload register 를 사용 합 니까? (0) | 2020.12.11 |