so are you trying to get a replication script setup to get your leads into MySQL?
I have a simple solution for you:
use this script:
PHP Code:
<?php
ini_set("soap.wsdl_cache_enabled","0");
require_once ('./includes/soapclient/SforcePartnerClient.php');
/*****************************************************************************
* This script uses ADODb, you must have ADOdb installed or in a common *
* folder to run this script. The best way to do this is to go to *
* http://adodb.sourceforge.net/ and download the latest version and install *
* it in your include_path in the php.ini file. *
******************************************************************************/
require_once ('./includes/adodb.inc.php');
$db = NewADOConnection('mysql');
//MySQL database connection information
$db->Connect("localhost","sfmysql","sfmysql","sf_live");
//Truncate current database to establish a refresh
$sql = "TRUNCATE TABLE sf_lyris_live_account";
if ($db->Execute($sql)) echo "<strong>Account Table Truncated</strong><br />";
//Salesforce Connection information
$wsdl = './includes/soapclient/partner.wsdl.xml';
$userName = "myuser";
$password = "mypass";
//setup connection
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName,$password);
//SOQL query for Object in Salesforce
$soql = "Select Id, IsDeleted, MasterRecordId, Name, Type, ParentId, BillingStreet, BillingCity FROM Account";
//Processes the query to get account information from Salesforce
$records = get_records($client,$soql,$db);
if ($records === false)
{
//mail("mike.simonds@maxim-ic.com","PHP Product2 Script Error","There has been an error in the product2 replication script\nPlease Check Script");
}
echo '<p>There are currently '.$records.' products:</p>';
$today = date("F j, Y, g:i a");
$end = 'Product2 Import script ended at '.$today.' and inserted '.$records.' into the database';
function get_records($connection,$query,$db)
{
//Set this to the number of records to process per batch
//200 is the minimum
$queryOptions = new QueryOptions(200);
$connection->setQueryOptions($queryOptions);
$response = $connection->query(($query),$queryOptions);
//for debugging
//echo '<pre>' . print_r($response,true) . '</pre>';
//exit;
if ($response->size > 0)
{
$records = $response->records;
// Cycles through additional responses if the number of records// exceeds the batch size
$count_records = 0;
while (!$response->done)
{
$records = $response->records;
set_time_limit(100);
ini_set("memory_limit","512M");
//Process curent $records
$current_count = store_in_db($records,$db);
if ($current_count === false)
{
return false;
}
else
{
$count_records += $current_count;
}
echo "processed ".$count_records." records<br />";
flush();
$response = $connection->queryMore($response->queryLocator,$queryOptions);
}
set_time_limit(100);
$records = $response->records;
//Process curent $records
//store the last set of records into the database
$current_count = store_in_db($records,$db);
if ($current_count === false)
{
return false;
}
else
{
$count_records += $current_count;
}
}
return $count_records;
}
/*Function to store records into
* database in chunks of the $queryOptions = new QueryOptions(200);*/
function store_in_db($records,$db)
{
$record_count = count($records);
//echo $record_count;
$rows_loaded = 0;
foreach ($records as $r)
{
echo '<pre>' . print_r($r,true) . '</pre>';
exit();
$pass_this['id'] = $r->Id;
//echo '<pre>' . print_r($pass_this,true) . '</pre>';
foreach ($r->fields as $key => $value)
{
$pass_this[$key] = addslashes($r->fields->$key);
}
$fields = implode(",",array_keys($pass_this));
$values = implode("','",array_values($pass_this));
$query = "INSERT INTO sf_lyris_live_account (".$fields.") VALUES ('".$values."')";
//executes and loads data coming from salesforce into table
if ($db->Execute($query))
{
$rows_loaded++;
}
else
{
echo $db->ErrorMsg()."<br />";
return false;
}
//exit;
}
return $rows_loaded;
}
?>
download ADOdb PHP class from the link on my main menu
Change the SOQL query, table names, paths to your phptoolkit and then also switch to the partner.wsdl file
This will work for you!!
~Mike
Bookmarks