Getting a SOAP response as a STD object. I'm trying to put this into a MySQL database.
for ($i = 0; $i < sizeof($getrelaties); $i++) {
$array = get_object_vars($getrelaties[$i]);
print "<pre>";
print_r($array);
print "</pre>";
print "<hr>";
foreach ($array as $key => $val) {
echo $key;
echo $val;
}
};
I'm getting the keys (which are the row names) and values. But kind of stuck on getting them to be separated by , so I can put them in a query.
This is one array out of the object:
(
[ID] => 4876260
[AddDatum] => 2015-09-24T09:16:00
[Code] => K0001
[Bedrijf] => Henk
[Contactpersoon] =>
[Geslacht] => m
[Adres] =>
[Postcode] =>
[Plaats] =>
[Land] =>
[Adres2] =>
[Postcode2] =>
[Plaats2] =>
[Land2] =>
[Telefoon] =>
[GSM] =>
[FAX] =>
[Email] => ******@gmail.com
[Site] =>
[Notitie] =>
[Bankrekening] =>
[Girorekening] =>
[BTWNummer] =>
[Aanhef] =>
[IBAN] =>
[BIC] =>
[BP] => B
[Def1] =>
[Def2] =>
[Def3] =>
[Def4] =>
[Def5] =>
[Def6] =>
[Def7] =>
[Def8] =>
[Def9] =>
[Def10] =>
[LA] => 0
[Gb_ID] => 0
[GeenEmail] => 0
[NieuwsbriefgroepenCount] => 0
)
The problem is that I want to put these arrays into the database. I don't want to hardcode the rows. Any suggestions?
Use serialize() to stringify the array and store in a BLOB or TEXT field in MySQL:
$serialized_array = serialize($array);
You can then SELECT this data back from the database as needed and make use of:
$data = unserialize($serialized_array);
This is 100% the way to go because the format of the arrays returned from the third-party SOAP service could change over time and you are not at the mercy of these changes and having to detect them and migrate your database schema accordingly etc.