Select MySQL rows with Japanese characters(选择带有日语字符的 MySQL 行)
问题描述
有谁知道在数据库中选择包含日语字符的行的可靠方法(使用 mySQL 或其他方式)?我的数据库中有很多行,其中一些只有字母数字字符,其中一些有日文字符.
Would anyone know of a reliable method (with mySQL or otherwise) to select rows in a database that contain Japanese characters? I have a lot of rows in my database, some of which only have alphanumeric characters, some of which have Japanese characters.
推荐答案
遇到字符集问题时的规则:
Rules when you have problem with character sets:
创建数据库时使用utf8编码:
While creating database use utf8 encoding:
CREATE DATABASE _test DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
确保所有文本字段(varchar 和 text)都使用 UTF-8:
Make sure all text fields (varchar and text) are using UTF-8:
CREATE TABLE _test.test (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE = MyISAM;
建立连接时,请在查询/更新数据库之前执行此操作:
When you make a connection do this before you query/update the database:
SET NAMES utf8;
使用 phpMyAdmin - 登录时选择 UTF-8.
With phpMyAdmin - Choose UTF-8 when you login.
将网页编码设置为 utf-8 以确保所有 post/get 数据都采用 UTF-8(或者你必须这样做,因为转换很痛苦..).PHP 代码(php 文件中的第一行或至少在任何输出之前):
set web page encoding to utf-8 to make sure all post/get data will be in UTF-8 (or you'll have to since converting is painful..). PHP code (first line in the php file or at least before any output):
header('Content-Type: text/html; charset=UTF-8');
确保您的所有查询均以 UTF8 编码编写.如果使用 PHP:
Make sure all your queries are written in UTF8 encoding. If using PHP:
6.1.如果 PHP 支持 UTF-8 格式的代码 - 只需用 UTF-8 格式编写文件.
6.1. If PHP supports code in UTF-8 - just write your files in UTF-8.
6.2.如果在没有 UTF-8 支持的情况下编译 php - 将您的字符串转换为 UTF-8,如下所示:
6.2. If php is compiled without UTF-8 support - convert your strings to UTF-8 like this:
$str = mb_convert_encoding($str, 'UTF-8', '<put your file encoding here');
$query = 'SELECT * FROM test WHERE name = "' . $str . '"';
这应该会起作用.
这篇关于选择带有日语字符的 MySQL 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:选择带有日语字符的 MySQL 行
基础教程推荐
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01