将 xml 字符串逐字转储到 mysql 数据库
我需要将 xml 字符串(作为 POST 参数进入 Web 服务)直接转储到 Mysql 数据库中。我正在写入的列目前的类型是“文本”,尽管我也尝试过 blob。
现在,当我保存字符串并稍后使用 sql 检索它时,它会以类似序列化的格式返回,如下所示:
a:1:{s:14:"<?xml_encoding";s:1502:"UTF-8?><record>
<nodes></nodes>
</record>";}
然而,我需要将该 xml 解析为 simplexml 对象,因此需要更好地形成它。
这就是我正在做的代码:
在Web服务中接受Post Param
使用ORM原则将其序列化并存储在数据库中,有点像
$record->xml_rec = serialize($_POST)
检索它并回显它。
奇怪的是,如果我反序列化并在重试时回显,我会得到一个数组。 print_f 上的数组看起来像这样,
Array
(
[<?xml_encoding] => UTF-8?><record>
<nodes></nodes>
</record>
)
但 simplexml 仍然无法解析。
这是 mysql 存储问题还是我对 POST 参数做错了什么?我尝试过 htmlspecialchars 将字符串保存在数据库中,但仍然存在类似的问题。
感谢任何帮助,谢谢
I need to dump an xml string (coming into a web service as a POST param), directly into a Mysql DB. The column into which I am writing is currently of type 'text', though I have tried blob as well.
Right now, when I save the string and retrieve it later on using sql, it comes back in a serialized like format, like this:
a:1:{s:14:"<?xml_encoding";s:1502:"UTF-8?><record>
<nodes></nodes>
</record>";}
Whereas, I need to parse that xml as a simplexml object, and hence need it to be better formed.
This is what I am doing codewise:
Accept Post Param in web service
Serialize and store it in DB using doctrine ORM, kind of like
$record->xml_rec = serialize($_POST)
Retrieve it and echo it.
Oddly enough, if I unserialize and echo is upon retrial, I get an array. The array looks like this upon print_f
Array
(
[<?xml_encoding] => UTF-8?><record>
<nodes></nodes>
</record>
)
Still not parse-able by simplexml.
Is this a mysql storage problem or am I doing something wrong with the POST params? I've tried htmlspecialchars to save the string in the db, but similar problems remain.
any help is appreciated, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的是一个“序列化”的 php 数组,您可以使用 PHP 的 unserialize 函数来反序列化。
What you have is a "serialized" php array that you can unserialize by using ... PHP's unserialize function.