2014-09-13 101 views
0

這是我的Web服務調用。SQL中的PHP對象選擇查詢

現在,它是硬編碼,但我會堅持它在用戶窗體後面。

它返回一個對象。如何使用SQL查詢使用該對象?我需要在產品,製造商處進行各種選擇查詢,在WHERE標準中我需要合同車輛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> 

回答

0
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(); 
} 
?> 

UPDATE基於您的評論

如果數據發生變化,則可能需要要知道你要查找的web服務,其指數,

echo $var->contractVehicle[2]; //will return OtherContractVehicle 
你可能想澄清你的問題或至少發表您的樣本數據,這樣我可以更多分析它

+0

好吧,我會研究這個。謝謝。澄清另一個目標:Web服務的響應將明顯改變。所以SQL查詢應該有一些變量或全局變量,所以我們不必總是重寫查詢。 – 2014-09-13 23:00:55

+0

更多說明: Evertime用戶提交表單,我正在調用Web服務。所以它可能會返回0 =>'ITSchedule70'或1 =>'ITCommodityProgram'或2 =>'OtherContractVehicle' 我有4輛合同車輛。 基於返回的合同車輛,我需要使用WHERE條件返回Products表中的結果。 所以像: SELECT * FROM'product' WHERE'contact_vehicle_id' = 2 所以很重要的一點是在需要動態的,因爲在飛行。 – 2014-09-14 02:07:57

+0

爲了更清晰起見,我修改了我的問題。請考慮。 – 2014-09-14 12:57:03