mysql - Drupal编码和节点插入

标签 mysql drupal drupal-6 character-encoding drupal-modules

我有一个用于存储提及(社交媒体搜索提及)的 CCK 类型。我认为其中的一些提及是 ASCII(我对这些东西的了解很少)。

我从 API 检索数据,然后使用 node_save 将其保存到 Drupal。

我的问题是,我应该使用什么来安全地将我得到的任何内容转换为 Drupal 和 MySQL 满意的格式?

我得到的特定 db_query 错误是毫无帮助的“第 3538 行 test1\includes\common.inc 中的警告”。好的。我已经追踪到它是编码的,因为我使用以下代码来确保输入安全,但它不适用于所有输入。

$node->title = htmlentities($item['title'], ENT_COMPAT, 'UTF-8');

它对一些 ASCII 字符很有效,比如那些方 block [] 等,但对这个“行けなくテもずずとユーミンガ聴きつづけます”就不行了。

我真的被困住了。 :(

更新:我从 PHP 得到的确切错误是“第 3538 行的 D:\sites\test1\includes\common.inc 中的警告”,该行显示为“if (db_query($query, $values)) { ".

更新 2:我已经确认我收到的数据的编码是 UTF8。现在这真的没有意义,我已经确认数据库中的排序规则是 utf8_general_ci。

更新 3:标题之一是:一个 Facebook 粉丝要花多少钱?1.07 美元

输出:

var_export(array_map('ord', str_split($node->title))

给了我有趣的问号字符 160(它是一个正方形,类似于 eclipse 中的 [])。

更新 4:MySQL 版本为 5.1.41,列的排序规则为 utf8_general_ci。

更新 5:我设法让 Drupal 使用 db_queryd 打印查询。有趣的是,现在我得到了确切的错误消息,而不是“警告”,但 Drupal 的日志中仍然没有这个错误!卧槽所以确切的sql是:

INSERT INTO node (vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) VALUES (0, 'sm_mention', '', 'How Much Does A Facebook Fan Cost?� $1.07 (Geoffrey A. Fowler/Digits)', 1, 1, 1298395302, 1298395302, 0, 0, 0, 0, 0, 0)

给出的错误是:不正确的字符串值:'\xA0 $1.0...' for column 'title' at row 1

老实说,这听起来像是不喜欢扩展的 ascii 字符。

更新 6:

 SHOW CREATE TABLE node: 

   CREATE TABLE `node` (
  `nid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `vid` int(10) unsigned NOT NULL DEFAULT '0',
  `type` varchar(32) NOT NULL DEFAULT '',
  `language` varchar(12) NOT NULL DEFAULT '',
  `title` varchar(255) NOT NULL DEFAULT '',
  `uid` int(11) NOT NULL DEFAULT '0',
  `status` int(11) NOT NULL DEFAULT '1',
  `created` int(11) NOT NULL DEFAULT '0',
  `changed` int(11) NOT NULL DEFAULT '0',
  `comment` int(11) NOT NULL DEFAULT '0',
  `promote` int(11) NOT NULL DEFAULT '0',
  `moderate` int(11) NOT NULL DEFAULT '0',
  `sticky` int(11) NOT NULL DEFAULT '0',
  `tnid` int(10) unsigned NOT NULL DEFAULT '0',
  `translate` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`nid`),
  UNIQUE KEY `vid` (`vid`),
  KEY `node_changed` (`changed`),
  KEY `node_created` (`created`),
  KEY `node_moderate` (`moderate`),
  KEY `node_promote_status` (`promote`,`status`),
  KEY `node_status_type` (`status`,`type`,`nid`),
  KEY `node_title_type` (`title`,`type`(4)),
  KEY `node_type` (`type`(4)),
  KEY `uid` (`uid`),
  KEY `tnid` (`tnid`),
  KEY `translate` (`translate`)
) ENGINE=InnoDB AUTO_INCREMENT=1700 DEFAULT CHARSET=utf8

最佳答案

\xA0 不是 UTF8 序列的有效开头。

具有 Unicode 代码点 0x00A0NO-BREAK SPACE 字符应编码为 0xC2A0 UTF8.

因此,您的输入字符串已损坏,它不是有效的 UTF8

关于mysql - Drupal编码和节点插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5028316/

相关文章:

java - JSP web 应用程序数据库连接无法加载

Drupal:如何以编程方式设置主题语言?

mysql - clostache/render 函数中是否有多个参数?

Drupal 7 默认 .htaccess

web-applications - Drupal 模块内部工作的隐喻

Drupal View 公开过滤器: Taxonomy Select List?

Drupal:显示成功/错误消息

drupal - head 标签中 src/href 属性末尾的奇怪字符

mysql - 选择 sql 中的查询并在每一行上进行测试

mysql - 对两个表使用 select 语句