SQL 选择查询中的 PHP 对象

标签 php mysql soap

这是我的网络服务调用。

现在,它是硬编码的,但我会将其粘贴在用户表单后面。

它返回一个对象。如何通过 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/

相关文章:

php - 如何捕获特征未找到错误 PHP 7

php - 从mysql的表中读取文件类型php的内容

php - 使用sql获取子项目?

java - SOAP 还是休息?具体项目

java - 我们可以在soapui中使用apache poi jar吗?

php 发送正常时间但 mysql 插入 00 :00:08 into table which is wrong

php - 如何执行存储在 MySQL 数据库中的 PHP?

Php & Mysql,从PHP-for循环中过滤出子查询进入MySQL语句

mysql - 优先执行 JOIN 关键字中的 WHERE 子句

ruby - 使用 Savon gem 在 Ruby 中使用 SOAP 服务