I need to display database table content in php using web service. in there i used WSDL service with php. this is i tried code,
Test.php
<?php
/* Initialize webservice with your WSDL */
$client = new SoapClient("http://localhost:23995/Service1.svc?wsdl");
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall("SelectUserDetails", array());
/* Print webservice response */
print_r($response);
?>
Output
> stdClass Object ( [SelectUserDetailsResult] => stdClass Object (
> [schema] => [any] => 1rooter12345rooter#gmail.com
> 2kal123ukkal#gmail.com 3sam123uksam#gmail.com 4net1234uknet#gmail.com
> ) )
How can i display these database values in HTML table with php
As per your output the response is an Object.If you are not familiar with PHP objects read this, As an example i can provide you the following code to access the Objects.
In PHP you can access and object by the following way :
$myObject = new stdClass(); //creating an object for demo
$myObject->name = 'My Name';
$myObject->address = 'My address1';
echo $myObject->name; // Output: My Name
echo $myObject->address; // Output: My address1
In the response, variable $response have the following members :
SelectUserDetailsResult // An Object with two members ('schema' & 'any'). In which schema is null, but you have some data in the member 'any'.
You can access the member 'any' as shown below :
$allEmails = $response->SelectUserDetailsResult->any;
By this way you can use this variable to print its value in any html.
Related
I have a problem with a collection.
When I do
echo ($homeTeam)
I get this result [{"Hometeam":3}]
But I want only 3 back.
Then I did this.
echo($homeTeam->Hometeam)
But then I get back error Property Home does not exist...
How to do this in a correct way?
Your input [{"Hometeam":3}] looks like json. First need to decode it:
$obj = json_decode($homeTeam);
Then to understand structure of data -- print it:
print_r($obj);
// output:
// Array
// (
// [0] => stdClass Object
// (
// [Hometeam] => 3
// )
//
// )
It is array of stdClass. So you can access to property Hometeam this way:
echo $obj[0]->Hometeam;
I am working on laravel app and I am saving my data in JSON encoded form as
{"name":"Ali","email":"testdc#gamil.com"}
It shows as above in db text field
In my method I am getting data as
function users($id, Request $request)
{
$method = $request->method();
if($request->isMethod('GET')) {
$users = DB::table('user_settings')->select('notification_setting')->first();
print_r( $notification_smtp);
die;
return view('setting/user');
}
}
Below is the output of the code above:
stdClass Object ( [notification_setting] => {"name":"Ali","email":"testdc#gamil.com"} )
If I try to decode it it gives an error as json_decode 2nd parameter should be string object passed
How can I get the response to this format?
stdClass Object ( [name] => Ali [email] => test#gmail.com )
How can I possibly achieve that?
Try, print_r( json_decode($notification_smtp->notification_setting) );
Did you try serialization? like get a tmp variable with parsed object
//your code
$users = DB::table('user_settings')->select('notification_setting')->first();
print_r( $notification_smtp);
die;
//try this
$tmp = (string) $user;
dd($tmp);
if not help, read laravel doc, its really good.
Laravel Serialization
If still no helping you, google serialization and unserialization ;)
I don't know how to work with such object, i need to get first and second one status value, tryed to convert it to json, but it gives me nothing. I just don't get it how to open array with such "_data:MailWizzApi_Params:private" name.
Source:
// SEARCH BY EMAIL
$response = $endpoint->emailSearch($myConfig["LIST-UNIQUE-ID"], $_GET["email"]);
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
I receive such answer
MailWizzApi_Params Object
(
[_data:MailWizzApi_Params:private] => Array
(
[status] => success
[data] => Array
(
[subscriber_uid] => an837jdexga45
[status] => unsubscribed
)
)
[_readOnly:MailWizzApi_Params:private] =>
)
In this case, you can't.
Because it's private field.
For public fields with "incorrect" names you can use snippet:
$name = '}|{';
$obj->$name;
So, let see to your property: [_data:MailWizzApi_Params:private].
It is private field of instance of MailWizzApi_Params class with _data name.
Let's google to it's implementation: Found
As you can see it has toArray public method. Just use it.
print_r($response->body->toArray());
It has ArrayAccess implemented also. So, $response->body['status'] or $response->body['data'] will works.
Thank you guys for fast answers, here is my dumb way if reading status value
(thanks, #Jose Manuel Abarca RodrÃguez)
$toJson = json_encode((array)$response->body);
$toJson = str_replace(array("\u0000MailWizzApi_Params\u0000_"), "", $toJson);
So we receive a normal json:
{"data":{"status":"success","data":{"subscriber_uid":"an837jdexga45","status":"unsubscribed"}},"readOnly":false}
And now we need just to decode it
$json = json_decode($toJson, true);
echo $json['data']['status'];
When I run following code in magento root
$client = new SoapClient('http://localhost/mymagento/index.php/api/v2_soap/index?wsdl=1', array('cache_wsdl' => WSDL_CACHE_NONE));
$session = $client->login('testuser', 'testuser');
$result = $client->salesOrderInfo($session,'100000097');
echo"<pre>";
print_r($result);
echo"</pre>";
I get [product_options] like following way in output
[product_options] => a:2:{s:15:"info_buyRequest";a:10:{s:4:"uenc";s:100:"aHR0cDovL2RlbW8uc2lnbWFpbmZvLmluOjgzL3JmZy9pbmRleC5waHAvbGFuZXNzZS1vY2Nhc2lvbmFsLXRhYmxlLXNldC5odG1s";s:7:"product";s:3:"115";s:15:"related_product";s:0:"";s:3:"qty";s:1:"1";s:13:"bundle_option";a:3:{i:47;s:3:"129";i:48;s:3:"131";i:49;s:3:"133";}s:17:"bundle_option_qty";a:3:{i:47;s:1:"1";i:48;s:1:"1";i:49;s:1:"1";}s:22:"select_super_attribute";a:1:{i:48;a:1:{i:182;s:3:"164";}}s:5:"block";a:1:{i:0;s:7:"options";}s:5:"awacp";s:1:"1";s:8:"no_cache";s:1:"1";}s:27:"bundle_selection_attributes";s:122:"a:4:{s:5:"price";d:159;s:3:"qty";d:1;s:12:"option_label";s:31:"Save on these additional pieces";s:9:"option_id";s:2:"49";}";}
How can I get the product price from this?
I there any direct function to access the price, instead of using unserialize ?
you must call the native PHP unserialize function as unserialize($result['product_options']) that should return you an array
I am trying to consume a SOAP based webservice uisng PHP. Following is the sample code. I need to know/learn how to access the retur'ed object elements?
Please note i am new to PHP
$url = 'http://www.webservicex.net/uszip.asmx?WSDL';
$soap = new SoapClient($url, array(
"trace" => 1, // enable trace to view what is happening
"exceptions" => 0, // disable exceptions
"cache_wsdl" => 0) );
try {
$result = $soap->GetInfoByZIP(array('USZip' => '97219'));
echo($result->$CITY);
//print_r( $soap->GetInfoByZIP(array("USZip" => "97219")));
} catch (SoapFault $e) {
echo "Error: {$e->faultstring}";
}
I get the following exception
Notice: Undefined variable: CITY
Fatal error: Cannot access empty property
However when I execute the commented line above it return the following response
stdClass Object
(
[GetInfoByZIPResult] => stdClass Object
(
[any] => <NewDataSet xmlns=""><Table><CITY>Portland</CITY><STATE>OR</STATE><ZIP>97219</ZIP><AREA_CODE>503</AREA_CODE><TIME_ZONE>P</TIME_ZONE></Table></NewDataSet>
)
)
So this means that data is being returned but i am not able to access it like the way done in .NET
Can anyone please help me how to access this object in PHP and why?
First of all, u're using $CITY variable to access $result property and you haven't defined it yet.
So if you want to get "CITY" property inside "result" object you should do it by "$result->City".
According to result you get - it's a xml string, not object. If you want to access string do it this way:
$result->GetInfoByZIPResult->any
You can load string with DomDocument or simplexml lib.