irandoct Posted October 16, 2013 Share Posted October 16, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283027-saving-stdclass-object-results-to-database/ Share on other sites More sharing options...
requinix Posted October 16, 2013 Share Posted October 16, 2013 $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. Quote Link to comment https://forums.phpfreaks.com/topic/283027-saving-stdclass-object-results-to-database/#findComment-1454180 Share on other sites More sharing options...
irandoct Posted October 16, 2013 Author Share Posted October 16, 2013 thank you for your reply. i'm not familiar with php (biginner)! please post complete code! Regards Mansour Quote Link to comment https://forums.phpfreaks.com/topic/283027-saving-stdclass-object-results-to-database/#findComment-1454183 Share on other sites More sharing options...
Ch0cu3r Posted October 16, 2013 Share Posted October 16, 2013 requinix did. Replace print_r ($value); with $string = $value->string; $string will be the data you want to serialize in the database? Quote Link to comment https://forums.phpfreaks.com/topic/283027-saving-stdclass-object-results-to-database/#findComment-1454184 Share on other sites More sharing options...
irandoct Posted October 16, 2013 Author Share Posted October 16, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283027-saving-stdclass-object-results-to-database/#findComment-1454185 Share on other sites More sharing options...
Solution irandoct Posted October 16, 2013 Author Solution Share Posted October 16, 2013 thank you guys! solved! Quote Link to comment https://forums.phpfreaks.com/topic/283027-saving-stdclass-object-results-to-database/#findComment-1454189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.