Technology Cares

Not Just another weblog

Archive for April, 2009

Import Salesforce data into your MySQL

Posted by Manish on April 16, 2009

The following script is the simple example to understand the process of importing the data from your Salesforce object to the MySQL database:


<?php
ini_set("soap.wsdl_cache_enabled", "0");
define(BASEDIR, 'lib/phptoolkit/soapclient/');
require_once (BASEDIR.'SforcePartnerClient.php');
require_once (BASEDIR.'SforceHeaderOptions.php');
require_once ('adodb/adodb.inc.php');
$db = NewADOConnection('mysql');
$db->Connect("localhost", "Username", "password", "TargetDatabaseName");
$wsdl = BASEDIR.'partner.wsdl.xml';
$userName = "user@somemail.sth";
$password = "passwordsecuritycode";
$client = new SforcePartnerClient();
$client->createConnection($wsdl);
$loginResult = $client->login($userName, $password);
$query = "Select Id,Name FROM Organization";
$response = $client->query($query);
echo '<p>Importing organizations From Salesforce...</p>';
foreach ($response->records as $r)
{
$pass_this['Id'] = $r->Id;
$pass_this['Name'] = addslashes($r->fields->Name);
$sql = $db->execute("INSERT INTO sforce_organization (id,name)
VALUES ('{$pass_this['Id']}','{$pass_this['Name']}' )");
}
echo '<p>Importing organizations From Salesforce Completed.</p>';
?>

Things to remember here are:
1. Configuring PHP

  • Search for the string “extension_dir” in php.ini. Uncomment it and set it equal to ext directory.
  • Turn on the required extensions “extension=php_curl.dll”, “extension=php_soap.dll”, “extension=php_openssl.dll” by uncommenting them
  • Install SSL Library files by copying the SSL library files from the PHP installation directory to your Windows system directory. The two files are libeay32.dll and ssleay32.dll.
  • 2. There is option of Parter WSDL and Enterprise WSDL to be used. I’ve used the Partner WSDL as it supports for the applications that are metadata driven.
    See here for more about these WSDL http://www.salesforce.com/us/developer/docs/sforce70/wwhelp/wwhimpl/common/html/wwhelp.htm?context=sforceAPI_WWHelp&file=sforce_API_partner_intro.html

    Posted in Uncategorized | Tagged: , , , | Leave a Comment »

    Regular expression to extract domain from the url

    Posted by Manish on April 10, 2009

    I had been trying to extract the domain from the URL that I receive in the yahoo pipe. Using the following rules in regular expression, we can extract the domain name in the general form of URL.
    Drag the ‘Regex’ from the ‘Operator’ and drop it to the workspace and
    Add following rules in it
    ^(http|https)://([\w-]+\.)+[\w-]+(/[\w- \+#@!~./?%&=]*)?$     ——>> extract $2
    Then add this rule to remove the trailing dot(.)
    (.*)\.$     ——>> extract $1

    Regex Operator

    Regex Operator


    Posted in Uncategorized | Tagged: | 1 Comment »

    OpenSSL support in PHP

    Posted by Manish on April 10, 2009

    Follow the following steps: ( I’ve xampp 1.7.0 installed in my windows XP machine for this)
    1. Uncomment
    extension=php_soap.dll
    extension=php_openssl.dll
    in the php.ini
    **The thing to note here is
    For PHP running under Apache, the directory from where php.ini is read is <apache dir>/bin and NOT <php dir>.

    2. Copy
    ssleay32.dll and
    libeay32.dll
    to your windows system32 directory
    ** The things to note here:
    the system searches for the dll file using the following order:
    1. The directory from which the application loaded.
    2. The windows\system32 directory.
    3. The windows\system directory.
    4. The windows directory.
    5. The current directory.
    6. The directories that are listed in the PATH environment variable.

    3. Reboot apache

    Posted in Uncategorized | Tagged: , | Leave a Comment »