Jump to content

saving stdClass Object results to database!


irandoct
Go to solution Solved by 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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.