声明
在尝试结束这个问题之前,请理解我已经将它发布在wordpress.se.com上,甚至提供了一笔无法回答的赏金。这让我相信这个问题可能与WordPress本身无关,但是我还不了解一些php / mysql的怪癖。我希望我已经为php / mysql的专家提供了足够的信息,让我知道可能出现的问题。
我遇到的问题是更新声明
UPDATE
`s_6_posts`
SET
`post_author` = 9,
`post_date` = '2012-04-11 20:40:05',
`post_date_gmt` = '2012-04-11 20:40:05',
`post_content` = '\n\n\n<div class=\"WordSection1\">\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style=\'font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red\'>This is a new document</span></b></p>\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style=\'font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red\'> </span></b></p>\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style=\'font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red\'>Test Test Test</span></b></p>\n\n</div>\n\n\n',
`post_content_filtered` = '',
`post_title` = '',
`post_excerpt` = '',
`post_status` = 'draft',
`post_type` = 'post',
`comment_status` = 'open',
`ping_status` = 'open',
`post_password` = '',
`post_name` = '',
`to_ping` = '',
`pinged` = '',
`post_modified` = '2012-04-11 20:40:05',
`post_modified_gmt` = '2012-04-11 20:40:05',
`post_parent` = 0,
`menu_order` = 0,
`guid` = 'https://qa.citivelocity.com/cvauthor/equitywire/?p=230'
WHERE
`ID` = 230
在php(WordPress代码库)中执行时,被切断了。 post_content字段的数据库中的结果是
<div class="WordSection1">
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:normal"><b><span style='font-size:9.0pt;font-family:"ArialNarrow","sans-serif";color:red'>This is a new document</span></b></p>
<p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height:normal"><b><span style='font-size:9.0pt;font-family:"ArialNarrow","sans-serif";color:red'>
问题
这里发生的事情是
<span style='font-size:9.0pt;font-family:"ArialNarrow","sans-serif";
color:red'> </span>
阻止,<span>
标记之间的空格被切断后的所有内容。我已经能够与其他数据包含空间一致地重现此问题。它似乎不是对场的大小限制,因为无论数据的长度如何,总是在空间发生切断。
这个SQL语句是在WordPress调试日志中输出的,我完全有理由相信它实际上是正在执行的语句。我通过MySQL客户端(Aqua Data Studio)运行相同的语句,并且没有发生切断。
我在CentOs上使用php 5.3运行Mysql 5.0.77。表格是MyISAM,校对是utf8_general_ci。
发布表架构:
CREATE TABLE `s_posts` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`post_author` bigint(20) unsigned NOT NULL DEFAULT '0',
`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content` longtext NOT NULL,
`post_title` text NOT NULL,
`post_excerpt` text NOT NULL,
`post_status` varchar(20) NOT NULL DEFAULT 'publish',
`comment_status` varchar(20) NOT NULL DEFAULT 'open',
`ping_status` varchar(20) NOT NULL DEFAULT 'open',
`post_password` varchar(20) NOT NULL DEFAULT '',
`post_name` varchar(200) NOT NULL DEFAULT '',
`to_ping` text NOT NULL,
`pinged` text NOT NULL,
`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content_filtered` text NOT NULL,
`post_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`guid` varchar(255) NOT NULL DEFAULT '',
`menu_order` int(11) NOT NULL DEFAULT '0',
`post_type` varchar(20) NOT NULL DEFAULT 'post',
`post_mime_type` varchar(100) NOT NULL DEFAULT '',
`comment_count` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `post_name` (`post_name`),
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
KEY `post_parent` (`post_parent`),
KEY `post_author` (`post_author`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
答案 0 :(得分:1)
您没有发布处理数据库交互的代码(如何构建和执行查询),但如果您prepare
字符串,则应按预期将数据完整地插入/更新。
我通过PDO::prepare
运行了字符串,结果是:
6774 Query update fulltext_test set post_content = '\\n\\n\\n<div class=\\\"WordSection1\\\">\\n\\n<p class=\\\"MsoNormal\\\" style=\\\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\\\"><b><span style=\'font-size:9.0pt;font-family:\\\"ArialNarrow\\\",\\\"sans-serif\\\";color:red\'>This is a new document</span></b></p>\\n\\n<p class=\\\"MsoNormal\\\" style=\\\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\\\"><b><span style=\'font-size:9.0pt;font-family:\\\"ArialNarrow\\\",\\\"sans-serif\\\";color:red\'> </span></b></p>\\n\\n<p class=\\\"MsoNormal\\\" style=\\\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\\\"><b><span style=\'font-size:9.0pt;font-family:\\\"ArialNarrow\\\",\\\"sans-serif\\\";color:red\'>Test Test Test</span></b></p>\\n\\n</div>\\n\\n\\n' WHERE id = 1 limit 1
注意所有转义符号的转义。我确认数据已成功插入mysql:
mysql> select * from fulltext_test\G
*************************** 1. row ***************************
id: 1
comment: this is a test comment right here 123453432
trimmed_comments: this
post_content: \n\n\n<div class=\"WordSection1\">\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style='font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red'>This is a new document</span></b></p>\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style='font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red'> </span></b></p>\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style='font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red'>Test Test Test</span></b></p>\n\n</div>\n\n\n
代码段:
<?php
$dsn = 'mysql:dbname=zzz_test;host=127.0.0.1';
try {
$dbo = new PDO($dsn, 'user', 'pass');
} catch (Exception $e) {
var_dump($e->getMessage());
}
$string = '\n\n\n<div class=\"WordSection1\">\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style=\'font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red\'>This is a new document</span></b></p>\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style=\'font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red\'> </span></b></p>\n\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:normal\"><b><span style=\'font-size:9.0pt;font-family:\"ArialNarrow\",\"sans-serif\";color:red\'>Test Test Test</span></b></p>\n\n</div>\n\n\n';
$sql = 'update fulltext_test set post_content = :postContent WHERE id = 1 limit 1;';
$stmt = $dbo->prepare($sql);
$stmt->bindValue(':postContent', $string);
$stmt->execute();
因此,在执行查询之前尝试转义字符串,你应该是金色的。为了记录,一切都是UTF-8;连接,整理等。