doulong2782 2015-01-13 17:23
浏览 26
已采纳

too long

I have to call a web service inside a while loop to submit several records from a database. The problem is that only the first record is postet. Seems that the webservice call makes terminate the while loop and the other records are not fetched anymore. The webservice call itself is correct. Someone can help me please ?

Here is the code :

error_reporting(E_ALL ^ E_NOTICE);
include("include/dbConn.php");

$client = new SoapClient("myservice.asmx?wsdl",array(
                        'exceptions'=>true,
                        'cache_wsdl'=>WSDL_CACHE_NONE,
                        'features' =>SOAP_WAIT_ONE_WAY_CALLS,
                        'encoding'=>'utf-8'));

$Context =array(
        "B1DBName" => "TestDB",
        "B1DefaultPriceListNumber" => "1",
        "B1UKStandardVatCode" => "O1",
);


$strSql="select * from custom_clients_insert_view";
$result = mysqli_query($conn,$strSql) or die("MySQL error: " . mysqli_error($conn) . "<hr>
Query: $strSql");  
while($row = mysqli_fetch_array($result)) 
{
    $Cust =array(
        "CardCode" => "",
        "WebPassword" => "",
        "EmailAddress" => $row['email'],
        "Title" => "",
        "FirstName" => $row['b_firstname'],
        "Surname" => $row['b_lastname'],
        "Telephone" => $row['b_phone'],
        "WebID" => $row['user_id'],
        "VATNumber" => "",
        "FaxNumber" => $row['fax'],
        "Telephone2" => "",
        "Organisation" => "",
        "MobilePhone" => ""
    );

    $params = array(
    'Context' => $Context,
    'WebsiteName' => "test2",
    'Cust' => $Cust,
    'ActiveCust' => true
    );

    try 
    {
        $result = $client->SubmitNewCustomerToB1($params);
        var_dump($result);
        echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
        /* do something on my log */
    } 
    catch (Exception $e) 
    {
        echo "Error!<br />";
        echo $e -> getMessage ();
        var_dump($result);
        echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
        /* do something on my log*/
    }

}
  • 写回答

1条回答 默认 最新

  • douzhong2954 2015-01-14 11:00
    关注

    The solution is to push the recordset in an array and then loop on the array using a for each statement.

    Here is the working code:

    include("include/dbConn.php");
    
    $CustArray = array();
    
    $client = new SoapClient("WSDL EDNPOINT HERE",array(
                            'exceptions'=>true,
                            'cache_wsdl'=>WSDL_CACHE_NONE,
                            'encoding'=>'utf-8'));
    
    $strSql="SELECT * FROM custom_clients_insert_view";
    $result = mysqli_query($conn,$strSql) or die("MySQL error: " . mysqli_error($conn) . "<hr>
    Query: $strSql");  
    while($row = mysqli_fetch_array($result)) 
    {
    
        $Context =array(
            "B1DBName" => "TESTDB",
            "B1DefaultPriceListNumber" => "1",
            "B1UKStandardVatCode" => "O1",
        );
    
    
        $WebsiteName =array(
            "WebsiteName"=> "Test webiste"
        );
    
        $ActiveCust =array(
                "ActiveCust" => "true"
        );
    
    
        $Cust =array(
            "CardCode" => "",
            "WebPassword" => "",
            "EmailAddress" => $row['email'],
            "Title" => "",
            "FirstName" => $row['b_firstname'],
            "Surname" => $row['b_lastname'],
            "Telephone" => $row['b_phone'],
            "WebID" => $row['user_id'],
            "VATNumber" => "",
            "FaxNumber" => $row['fax'],
            "Telephone2" => "",
            "Organisation" => "",
            "MobilePhone" => ""
        );
    
        $params = array(
        'Context' => $Context,
        'WebsiteName' => $WebsiteName,
        'Cust' => $Cust,
        'ActiveCust' => $ActiveCust
        );
    
        array_push($CustArray, $params);
    }
    
    foreach ($CustArray as $params) 
    {
        try 
        {
            $result = $client->SubmitNewCustomerToB1($params);
            var_dump($result);
            echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
        } 
        catch (Exception $e) 
        {
            echo "Error!<br />";
            echo $e -> getMessage ();
            var_dump($result);
            echo "<br><br> VALUE:" . $result->SubmitNewCustomerToB1Result;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么