You need to sign in to do that
Don't have an account?
HELP!! PHP Salesforce to Mysql Database script
Hi I am having problems getting all the records from salesforce to my mysql database. It seems to copy the first 50 records and then gives an error saying that Error 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sullivan', '', '', '', '')' at line 1. This is the code that I am using to fetch the data. There are a total of 15,570 records in salesforce.com and by ommiting the function show_error() only 15,472 records are copied into my local database.
function update_contact($mySforceConnection){ echo"**************************************<br>"; echo"started updating contact table<br>"; try { $query = "SELECT AccountId,Email,FirstName,Phone_1__c,Id,MobilePhone,Name,Phone FROM Contact ORDER BY CreatedDate DESC NULLS FIRST"; $options = new QueryOptions(100); $connection = mysql_open(); //opens a connection $mySforceConnection->setQueryOptions($options); $response = $mySforceConnection->query($query); !$done = false; //echo "Size of records: ".$response ->size."\n"; if ($response->size > 0) { while (!$done) { foreach ($response->records as $record) { $insert = "insert into contact(Id, AccountId, FirstName, Name, MobilePhone, HomePhone, Email, Phone) " . "values ('$record->Id', '$record->AccountId', '$record->FirstName', '$record->Name', '$record->MobilePhone', '$record->Phone_1__c', '$record->Email', '$record->Phone')";//query for insert $result = mysql_query($insert, $connection) or show_error($record); } if ($response->done != true) { //echo "***** Get Next Chunk *****\n"; try { $response = $mySforceConnection->queryMore($response->queryLocator); } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } } else { $done = true; } } } } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } echo"finished updating contact table<br>"; mysql_close($connection);//close connection }
THe structure of my table in mysql database is:
Id(varchar(18)), AccountId(varchar(18)), FirstName(varchar(40)), Name(varchar(121)), MobilePhone(varchar(40)), HomePhone, Email and Phone are also varchar(40).
Can somebody please help me? I am using the enterprise WSDL.
You should escape the values you're trying to insert.
Try mysql_real_escape_string()