这是我的网络服务调用。
现在,它是硬编码的,但我会将其粘贴在用户表单后面。
它返回一个对象。如何通过 SQL 查询使用该对象?我需要对产品、制造商进行各种选择查询,在 WHERE 条件中我需要契约(Contract)车辆 ID。
<html>
<head>
<title>Call to Navigator Web Service</title>
</head>
<body>
<?php
$param = array('commodity' => 'LAPTOP', 'placeOfPerformance' => array('location' => 'LSA' , 'lsaStates' => 'NY', 'VA', 'TX', 'oconusStates' => 'ALASKA', 'EMEA'), 'equipmentType' => 'ANY', 'socioEconomicObjective' => 'NONE', 'agencyCode' => '007',);
$client = new SoapClient('https://sso-test.fas.gsa.gov/mpdev/navigator/wsdl');
$results = $client->__soapCall('retrieveContractVehicles', array('parameters' => $param));
print_r($results);
echo ("<br />");
echo ("End of line");
?>
</body>
</html>
最佳答案
class test_object
{
public $contractVehicle = array(
0=>'ITSchedule70',
1=>'ITCommodityProgram'
);
function get_contract()
{
return $this->contractVehicle;
}
}
$var = new test_object(); //let us say this is the part you are getting the result from web service
echo $var->contractVehicle[0]; //this is how you will get ITSchedule70
结果:
ITSchedule70
如何插入查询是什么意思?你的意思是如何保存它?我不确定这个问题,但这就是我插入查询的方式(保存到数据库)
<?php
define('DB_IP',''); //this is your server's IP/name
define('DB_USERNAME',''); //database username
define('DB_PASSWORD',''); //database password
define('DB_DATABASE',''); //default database to use
class test_object //I do not have the webservice object so I just add this
{
public $contractVehicle = array(
0=>'ITSchedule70',
1=>'ITCommodityProgram'
);
function get_contract()
{
return $this->contractVehicle;
}
}
$var = new test_object(); //lets say this is the variable you will save the result when you invoke the webservice
try
{
//check for connection
$connection = mysqli_connect(DB_IP,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(!$connection)
{
$db_conn_err = "Unable to Connect to Database ERROR: ". mysqli_connect_error($connection);
throw new Exception($db_conn_err);
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
$qry_trans = "INSERT INTO `Product`
(
`id`,
`other_column`,
`ContractVehicle`
)
VALUES
(
1, //use your own value depending on your table requirements
'use your own values',
$var->contractVehicle[0] //ITSchedule70
);";
try
{
$result = mysqli_query($connection, $qry_trans ); //execute the query
if( $result )
{
echo 'Successfully saved!';
}
else
{
$err = 'Unable to insert into table err:'.mysqli_error($connection).'<br>';
throw new Exception($err);
}
}
catch(Exception $e)
{
echo $e->getMessage();
}
?>
根据您的评论进行更新
如果数据发生变化,您可能想知道要查找 Web 服务中的哪个索引,
echo $var->contractVehicle[2]; //will return OtherContractVehicle
您可能想澄清您的问题或至少发布您的示例数据,以便我可以对其进行更多分析。
关于SQL 选择查询中的 PHP 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25826015/