我必须在while循环中调用Web服务才能从数据库中提交几条记录。 问题是只有第一个记录是postet。 似乎webservice调用使终止while循环并且不再获取其他记录。 webservice调用本身是正确的。 有人可以帮我吗?
以下是代码:
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>\nQuery: $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*/
}
}
答案 0 :(得分:1)
解决方案是将记录集推送到数组中,然后使用for each语句循环数组。
以下是工作代码:
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>\nQuery: $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;
}
}