PHP Code:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
include_once ('/opt/lampp/htdocs/adodb/adodb.inc.php');
require_once ('/opt/lampp/htdocs/includes/sfdc_new.inc');
$db = ADONewConnection("mysql");
//MySQL database connection information
$db->Connect("localhost", "mike", "mas4155", "salesforce");
$db->debug = true;
//Truncate current database to establish a refresh
$table = "sforce_user";
$sql = "TRUNCATE TABLE $table";
$db->Execute($sql);
if ($db)
{
echo "table truncated\n";
}
else
{
echo "Failed";
var_dump($db->ErrorMsg());
exit();
}
$soql = "Select Id, Username, LastName, FirstName, Name, CompanyName, Division, Department, Title, Street, City, State, PostalCode, Country, Email,
Phone, Fax, MobilePhone, Alias, IsActive, TimeZoneSidKey, UserRoleId, LocaleSidKey, ReceivesInfoEmails, ReceivesAdminInfoEmails, EmailEncodingKey,
ProfileId, LanguageLocaleKey, EmployeeNumber, LastLoginDate, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp,
OfflineTrialExpirationDate, OfflinePdaTrialExpirationDate, UserPermissionsMarketingUser, UserPermissionsOfflineUser, UserPermissionsAvantgoUser,
ForecastEnabled FROM User";
//Processes the query to get account information from Salesforce
$records = get_records($client, $soql, $db);
exit;
function get_records($connection, $query, $db)
{
//Set this to the number of records to process per batch
//200 is the minimum
$queryOptions = new QueryOptions(2000);
$connection->setQueryOptions($queryOptions);
$response = $connection->query(($query), $queryOptions);
//echo '<pre>' . print_r($response, true) . '</pre>';
//for debugging
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\n";
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;
}
}
echo "processed " . $count_records . " records\n";
return $count_records;
}
function store_in_db($records, $db)
{
global $table;
$record_count = count($records);
$rows_loaded = 0;
foreach ($records as $r)
{
$pass_this['id'] = $r->Id;
foreach ($r->fields as $key => $value)
{
//$pass_this[$key] = addslashes($r->fields->$key);
$pass_this[$key] = $r->fields->$key;
}
$insertSQL = $db->AutoExecute($table, $pass_this, 'INSERT');
$rows_loaded++;
}
return $rows_loaded;
}
?>
Bookmarks