我有一条像这样的推文: https://twitter.com/ATD_hashtagger/status/591204518253170689
#myownlittletest 3
当我尝试将其添加到我的数据库时,它变为:
??????????????????????????????????????????????? ?????????????????????????????????????????????????? ??????????????? #myownlittletest 1
我的表具有排序规则utf8mb4_general_ci
,同样的排序规则也用于插入它的字段(TEXT
)。
该值将插入名为text
的列中。
我有一个非常简单的查询来插入它:
INSERT INTO `posts_twitter` (`hashtagId`, `coordinates`, `created`, `filterlevel`, `postId`, `language`, `profanity`, `retweeted`, `text`, `truncated`, `userId`, `username`, `userFullname`, `media`, `mediaType1`, `media1`, `mediaType2`, `media2`, `mediaType3`, `media3`, `mediaType4`, `media4`) VALUES (:hashtagId, POINT(:coordinatesLat,:coordinatesLon), :created, :filterlevel, :postId, :language, :profanity, :retweeted, :text, :truncated, :userId, :username, :userFullname, COALESCE(:media1,:media2,:media3,:media4), :mediaType1, :media1, :mediaType2, :media2, :mediaType3, :media3, :mediaType4, :media4) ON DUPLICATE KEY UPDATE `hashtagId` = `hashtagId`
这些参数由PDO绑定:
array(22) {
["coordinatesLat"]=>
NULL
["coordinatesLon"]=>
NULL
["created"]=>
int(1429788536)
["filterlevel"]=>
string(3) "low"
["postId"]=>
int(591202087243014145)
["language"]=>
string(3) "und"
["profanity"]=>
bool(false)
["retweeted"]=>
bool(false)
["text"]=>
string(131) " #myownlittletest 1"
["truncated"]=>
bool(false)
["userId"]=>
int(2805078403)
["username"]=>
string(14) "ATD_hashtagger"
["userFullname"]=>
string(18) "Hashtag aggregator"
["media1"]=>
NULL
["mediaType1"]=>
NULL
["media2"]=>
NULL
["mediaType2"]=>
NULL
["media3"]=>
NULL
["mediaType3"]=>
NULL
["media4"]=>
NULL
["mediaType4"]=>
NULL
["hashtagId"]=>
int(3)
}
我的表是使用以下查询创建的:
CREATE TABLE IF NOT EXISTS `local_sysDB`.`posts_twitter` (
`hashtagId` INT NOT NULL,
`postId` CHAR(20) NOT NULL,
`coordinates` POINT NULL,
`created` INT(20) UNSIGNED NOT NULL,
`filterlevel` VARCHAR(45) NOT NULL,
`language` CHAR(11) NOT NULL,
`profanity` TINYINT(1) NOT NULL,
`retweeted` TINYINT(1) NOT NULL,
`text` CHAR(240) NOT NULL,
`truncated` TINYINT(1) NOT NULL,
`userId` INT UNSIGNED NOT NULL,
`username` CHAR(15) NOT NULL,
`userFullname` CHAR(20) NOT NULL,
`media` VARCHAR(255) NULL COMMENT 'First encountered media of COALESCE',
`mediaType1` CHAR(5) NULL,
`media1` VARCHAR(255) NULL,
`mediaType2` CHAR(5) NULL,
`media2` VARCHAR(255) NULL,
`mediaType3` CHAR(5) NULL,
`media3` VARCHAR(255) NULL,
`mediaType4` CHAR(5) NULL,
`media4` VARCHAR(255) NULL,
PRIMARY KEY (`hashtagId`, `postId`),
INDEX `posts_coordinates` (`coordinates` ASC) COMMENT 'should be SPATIAL INDEX',
FULLTEXT INDEX `posts_twitter_search` (`text` ASC, `username` ASC, `userFullname` ASC),
CONSTRAINT `posts_twitter_posts`
FOREIGN KEY (`hashtagId` , `postId`)
REFERENCES `local_sysDB`.`posts` (`hashtagId` , `postId`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;
此查询结果为:
Name Type Collation Attributes Null Default
hashtagId int(11) No None
postId char(20) utf8mb4_general_ci No None
coordinates point Yes NULL
created int(20) UNSIGNED No None
filterlevel varchar(45) utf8mb4_general_ci No None
language char(11) utf8mb4_general_ci No None
profanity tinyint(1) No None
retweeted tinyint(1) No None
text char(240) utf8mb4_general_ci No None
truncated tinyint(1) No None
userId int(10) UNSIGNED No None
username char(15) utf8mb4_general_ci No None
userFullname char(20) utf8mb4_general_ci No None
media varchar(255) utf8mb4_general_ci Yes NULL
mediaType1 char(5) utf8mb4_general_ci Yes NULL
media1 varchar(255) utf8mb4_general_ci Yes NULL
mediaType2 char(5) utf8mb4_general_ci Yes NULL
media2 varchar(255) utf8mb4_general_ci Yes NULL
mediaType3 char(5) utf8mb4_general_ci Yes NULL
media3 varchar(255) utf8mb4_general_ci Yes NULL
mediaType4 char(5) utf8mb4_general_ci Yes NULL
media4 varchar(255) utf8mb4_general_ci Yes NULL
运行此查询时:SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
它在phpMyAdmin中给出了这个结果:
Variable_name Value
character_set_client utf8
character_set_connection utf8
character_set_database utf8mb4
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
collation_connection utf8_general_ci
collation_database utf8mb4_general_ci
collation_server latin1_swedish_ci
我使用以下MySQL版本:
服务器:通过UNIX套接字的Localhost
服务器类型:MySQL服务器版本:5.6.24-log - MySQL社区服务器(GPL)
协议版本:10
服务器字符集:UTF-8 Unicode(utf8)
我已经发现使用BLOB
字段可能会有所帮助,但我无法在字段FULLTEXT
上使用text
索引。
有没有办法将表情符号保存到我的数据库而不将其转换为问号?
这不是重复,因为我的字符不是空白,但在问号中,提供的主题中的解决方案也无效。