Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将XML-RPC数据导入SQL表_Php_Sql_Import_Xml Rpc - Fatal编程技术网

Php 将XML-RPC数据导入SQL表

Php 将XML-RPC数据导入SQL表,php,sql,import,xml-rpc,Php,Sql,Import,Xml Rpc,我想说实话,所以,我会从一开始就告诉你,我对这种东西不太在行。我是PHP/SQL等的新手,目前遇到的这个问题让我有点不知所措,因此,如果有任何帮助,我将不胜感激。:) 我的问题是下一个: Name: "money.received" Arguments: array ("API Key", "PlayerName","Minimum Timestamp (0 is fine for full history)") Returns: array(array (from, amount, time

我想说实话,所以,我会从一开始就告诉你,我对这种东西不太在行。我是PHP/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;
}
?>
在一个网站上,我可以使用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;
}
?>

这是我准备好的代码:

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;
}
?>

我实际上还没有查看xml的格式,所以这是示例代码,而不是用于插入的代码,如果有机会,我会回来仔细查看您的数据

我使用类似这样的方法使用ms_sql中的存储过程导入xml。 我将xml作为参数传递给存储过程。然后将xml插入临时表中,然后我可以使用标准sql处理临时表

CREATE PROCEDURE [dbo].[procXMLImport] 
@pvchCustomXML varchar(max) = null, 
@piError int = 0 output,    -- return error code as output parameter for c++ code
@pvchError varchar(200) = '' output

as
begin

    declare @rc int;

    create table #import
    ( id int, val varchar(200)) 


    if ( @pvchCustomXML is not null)
    begin

        declare @xml_id int

        exec @rc = sp_xml_preparedocument @xml_id OUTPUT, @pvchCustomXML ;

        if (@@error != 0 or @rc != 0) 
        begin
            exec sp_xml_removedocument @xml_id;

            set @pvchError = 'sp_xml_preparedocument failed'
            set @piError = -1
            return @piError;
        end 

        -- put values into temps table
        -- not strictly required but seperates potential errors

        insert  #import
        select  id, val

        from    
        openxml ( @xml_id , 'Custom/Lines/Line', 1 ) -- 'Custom/Lines/Line' specifies where in the xml structure to extract the data from
        with    ( id int, val varchar(200) ) 

        if (@@error != 0) 
        begin
            exec sp_xml_removedocument @xml_id;
            set @pvchError = 'import failed'
            set @piError = -2
            return @piError;
        end;

        --clean up xml , no longer required
        exec sp_xml_removedocument @xml_id;

    end

    select * from #import   
end
Mysql有一个函数ExtractValue(),它的用途似乎与“fromOpenXML”类似

这家伙似乎有一些php类用于将mysql与php数据结合使用:


而且

我实际上还没有研究xml的格式,所以这是示例代码,而不是用于插入的代码,如果有机会,我会回来仔细查看您的数据

我使用类似这样的方法使用ms_sql中的存储过程导入xml。 我将xml作为参数传递给存储过程。然后将xml插入临时表中,然后我可以使用标准sql处理临时表

CREATE PROCEDURE [dbo].[procXMLImport] 
@pvchCustomXML varchar(max) = null, 
@piError int = 0 output,    -- return error code as output parameter for c++ code
@pvchError varchar(200) = '' output

as
begin

    declare @rc int;

    create table #import
    ( id int, val varchar(200)) 


    if ( @pvchCustomXML is not null)
    begin

        declare @xml_id int

        exec @rc = sp_xml_preparedocument @xml_id OUTPUT, @pvchCustomXML ;

        if (@@error != 0 or @rc != 0) 
        begin
            exec sp_xml_removedocument @xml_id;

            set @pvchError = 'sp_xml_preparedocument failed'
            set @piError = -1
            return @piError;
        end 

        -- put values into temps table
        -- not strictly required but seperates potential errors

        insert  #import
        select  id, val

        from    
        openxml ( @xml_id , 'Custom/Lines/Line', 1 ) -- 'Custom/Lines/Line' specifies where in the xml structure to extract the data from
        with    ( id int, val varchar(200) ) 

        if (@@error != 0) 
        begin
            exec sp_xml_removedocument @xml_id;
            set @pvchError = 'import failed'
            set @piError = -2
            return @piError;
        end;

        --clean up xml , no longer required
        exec sp_xml_removedocument @xml_id;

    end

    select * from #import   
end
Mysql有一个函数ExtractValue(),它的用途似乎与“fromOpenXML”类似

这家伙似乎有一些php类用于将mysql与php数据结合使用:


您可以发布XML-RPC调用返回的有效负载的副本吗?XML-RPC只是一种进行远程函数调用的方法。它应该像函数调用一样,返回一些东西。根据somethings格式的不同,它将决定您需要做什么来将其插入数据库。您可以发布XML-RPC调用返回的有效负载的副本吗?XML-RPC只是一种进行远程函数调用的方法。它应该像函数调用一样,返回一些东西。根据somethings格式的不同,它将决定您需要做什么才能将其插入DB。SQL Server 2005/2008极大地改进了他们处理XML的方法。虽然上面建议的代码仍然可以使用,但使用xml数据类型的新语法要简单得多。SQL Server 2005/2008极大地改进了他们处理xml的方法。虽然上面建议的代码仍然可以使用,但使用xml数据类型的新语法要简单得多。