I was working on this script over the past few days and in my orginal tutorial none of the fields that I supplied used or discussed any NUMERIC fields. I added two numeric fields to test the extraction process and I could not get the local array that I had created to be populated with the data coming in from the object from salesforce. This is just related to developers that are working with MySQL!
My orginal tutorial, Salesforce – PHP To MySQL Database Replication Script, did not have any numeric fields to work with, therefore I did not take this into consideration. For that I am sorry. So in order to work with numeric fields, such as currency, from salesforce.com, here is what worked for me:
Orginal Code:
PHP Code:
$pass_this['numeric_field1__c'] = $r->fields->numeric_field1__c;
$pass_this['numeric_field2__c'] = $r->fields->numeric_field2__c;
the array > $pass_this was not being populated from the $r->fields object and it really threw me for a loop. I could not figure out why the fields were not being passed and it really started to get on my nerve. Then I remember that sometimes you have to tell PHP to cast variables to treat them a specific way. Look at my new php snippet:
PHP Code:
$pass_this['numeric_field1__c'] = (string)$r->fields->numeric_field1__c;
$pass_this['numeric_field2__c'] = (string)$r->fields->numeric_field2__c;
By using the (string) function or cast, this makes PHP treat the object or variable as a string and then the value will pass to the array. You can also use (float) if you want to pass these values as a numeric field with decimals.
Here is a full example with a complete array being passed from $r to $pass_this (see attached)
Bookmarks