Jump to content

saving stdClass Object results to database!


irandoct

Recommended Posts

Hi,

i'm using SoapClient. i want to save result of SoapClient to a mysql database. my php code for webservice:

        $client = new SoapClient("http://sms-webservice.ir/v1/v1.asmx?wsdl");
        $params = array(
            'Username'=>$username,
            'PassWord'=>$password,
            'numberOfMessages'=>$numberOfMessages,
            'destNumber'=>$destNumber,
            'ErrNum'=>$ErrNum,
        );
        $result = $client->GetAllMessages( $params );
        if (is_soap_fault($result)) {
        echo '<h2>Fault:</h2><pre>';
        print_r($result);
       echo '</pre>';
       } else {
       $res = $result->GetAllMessagesResult->ArrayOfString;
       echo "<div dir=ltr>";
       foreach($res as $key => $value){
       print_r ($value);
       //$MyResult = ew_Execute("INSERT INTO receivedsms (MessageID, ReceiverNumber, SenderNumber, MessageTxt, ReceiveDate) VALUES ('', '', '', '', '')");
       }
       echo "</div>";
        //end get messages
        }

my SoapClient results return the following data:

stdClass Object ( [string] => Array ( [0] => 32979916 [1] => 5000206060500 [2] => 9140544602 [3] => A [4] => 10/16/2013 11:13:03 PM ) ) stdClass Object ( [string] => Array ( [0] => 32979917 [1] => 5000206060500 [2] => 9140544602 [3] => B [4] => 10/16/2013 11:13:13 PM ) ) stdClass Object ( [string] => Array ( [0] => 32979923 [1] => 5000206060500 [2] => 9140544602 [3] => C [4] => 10/16/2013 11:13:23 PM ) )

Please help me complete my code to save the soapclient results to mysql table!

 

Regards

Mansour

 

$value comes from the ArrayOfString array and it is an stdClass. The only member of that class is "string" which is also an array.

$string = $value->string;
Now $string is an array with the five bits of data you want.

Hi,

I changed my code to:

		$client = new SoapClient("http://sms-webservice.ir/v1/v1.asmx?wsdl");
        $params = array(
            'Username'=>$username,
            'PassWord'=>$password,
			'numberOfMessages'=>$numberOfMessages,
			'destNumber'=>$destNumber,
			'ErrNum'=>$ErrNum,
        );
        $result = $client->GetAllMessages( $params );
        if (is_soap_fault($result)) {
        echo '<h2>Fault:</h2><pre>';
        print_r($result);
       echo '</pre>';
       } else {
	   $res = $result->GetAllMessagesResult->ArrayOfString;
       foreach($res as $key => $value){
       $string = $value->string;
	   $MyResult = ew_Execute("INSERT INTO receivedsms (MessageID, ReceiverNumber, SenderNumber, MessageTxt, ReceiveDate) VALUES ('".$string['0']."', '".$string['1']."', '".$string['2']."', '".$string['3']."', '".$string['4']."')");
       }

my script return the following error:

Notice: Trying to get property of non-object in C:\xampp\htdocs\ourclinic\sendmessage.php on line 290

 

Please advise!

Mansour

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.