将 XML-RPC 数据导入 SQL 表
我想说实话,所以,我从一开始就告诉你,我不太擅长这种事情。我是 PHP/SQL 等方面的新手,我现在有点被这个问题困扰,所以,任何帮助将不胜感激。 :)
我的下一个问题是:
在一个网站上,我拥有使用 API 的访问权限(密钥)。但是,问题是它的 XML-RPC。我已阅读所有指南,并尝试通过谷歌搜索某种解决方案,但我没有运气。
我想将 XML-RPC 数据直接导入到现有的 SQL 表中。
这是我想用来调用我需要的数据的方法:
Name: "money.received"
Arguments: array ("API Key", "PlayerName","Minimum Timestamp (0 is fine for full history)")
Returns: array(array (from, amount, timestamp))
这是我已经准备好的代码:
<?php
$request2 = xmlrpc_encode_request("money.received", array('key','bware96', '0'));
$context2 = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",
'content' => $request2
)));
$file2 = file_get_contents("http://www.test.net/xmlrpc.php", false, $context2);
$response2 = xmlrpc_decode($file2);
if ($response2 && xmlrpc_is_fault($response2)) {
trigger_error("xmlrpc: $response2[faultString] ($response2[faultCode])");
} else {
echo "<B>Money Received</B><BR>";
# var_dump($response2);
echo "<BR>";
echo "<table border='1'>";
echo displayTree($response2);
echo "</table>";
}
function displayTree($var) {
$newline = "\n";
foreach($var as $key => $value) {
if (is_array($value) || is_object($value)) {
$value = $newline . "<tr>" . displayTree($value) . "</tr>";
}
if (is_array($var)) {
if (!stripos($value, "<li>")) {
$output .= "<td>" . $value . "</td>" . $newline;
}
else {
$output .= $value . $newline;
}
}
}
return $output;
}
?>
您可以在此处找到该代码的结果: 测试页面
所以是的,如您所见,函数 displayTree 对其进行了排序上,其中的所有数据xml。但是,我想将该数据导入到 SQL,但问题是我不知道如何操作。
我想将每一行分别导入到名为 ,,client" 的 SQL 表中,这样我以后就可以将其整理出来。:)
所以,请提供任何帮助,即使它只是链接到一些实际有用的页面,其中我可以找到我的解决方案:)
提前致谢,
劳伦
I want to be honest, so, I will tell you from the start that I'm not too good with this kind of stuff. I'm new to PHP/SQL etc., and I'm kinda stucked with this problem I have at this moment, so, any help will be appreciated. :)
My problem is next:
On one website, I have access(key) for using API. But, problem is that its XML-RPC. I have read all the guides, and try googling for some sort of solution, but I had no luck with that.
I want to import XML-RPC data directly to existing SQL table.
This is the method I want to use to call data I need:
Name: "money.received"
Arguments: array ("API Key", "PlayerName","Minimum Timestamp (0 is fine for full history)")
Returns: array(array (from, amount, timestamp))
And this is the code I have allready:
<?php
$request2 = xmlrpc_encode_request("money.received", array('key','bware96', '0'));
$context2 = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",
'content' => $request2
)));
$file2 = file_get_contents("http://www.test.net/xmlrpc.php", false, $context2);
$response2 = xmlrpc_decode($file2);
if ($response2 && xmlrpc_is_fault($response2)) {
trigger_error("xmlrpc: $response2[faultString] ($response2[faultCode])");
} else {
echo "<B>Money Received</B><BR>";
# var_dump($response2);
echo "<BR>";
echo "<table border='1'>";
echo displayTree($response2);
echo "</table>";
}
function displayTree($var) {
$newline = "\n";
foreach($var as $key => $value) {
if (is_array($value) || is_object($value)) {
$value = $newline . "<tr>" . displayTree($value) . "</tr>";
}
if (is_array($var)) {
if (!stripos($value, "<li>")) {
$output .= "<td>" . $value . "</td>" . $newline;
}
else {
$output .= $value . $newline;
}
}
}
return $output;
}
?>
The result of that code you can find here: Test page
So yea, as you can see, function displayTree kinda sorts it up, all the data in that xml. But, I want to import that data to SQL, and the problem is that I dont know how.
I want to import each of those rows separately into SQL table called ,,client", so I can later sort it out. :)
So, please, any help will be reaaaaaally appreaciated, even if its just link to some actually helpfull page where I can find my solution. :)
Thanks in advance,
Lauren
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上没有查看您的 xml 格式,所以这是示例代码,而不是用于插入的代码,如果我有机会晚一些,我会回来仔细查看您的数据。
我使用类似的方法通过 ms_sql 中的存储过程导入 xml。
我将 xml 作为参数传递给存储过程。然后将 xml 插入到临时表中,然后我可以使用标准 sql 对其进行处理。
Mysql 有一个函数 ExtractValue(),它的用途似乎与“from openxml”类似。
http://dev.mysql.com/doc/refman/5.1 /en/xml-functions.html
这家伙似乎有一些 php 类用于将 mysql 与 php 数据一起使用:
http://www .phpclasses.org/package/782-PHP-Insert-XML-in-MySQL-and-export-MySQL-to-XML.html
和
I haven't actually looked at the format of your xml, so this is sample code, not code that will do your insert, If I have a chance late I come back and have a closer look at your data.
I use something like this to import xml using a stored procedure in ms_sql.
I pass xml as a parameter to the stored procedure. The xml is then inserted into a temp table, which I can then process using standard sql.
Mysql has a function ExtractValue(), which seems to have a similar purpose to 'from openxml'.
http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html
and this guy seems to have some php classes for using mysql with php data:
http://www.phpclasses.org/package/782-PHP-Insert-XML-in-MySQL-and-export-MySQL-to-XML.html
and