Easysoft ODBC-Salesforce Driver

How do I connect PHP to Salesforce.com on Linux or UNIX?

Last Reviewed:
28th January 2014

Use the Salesforce.com ODBC Driver to connect PHP to Salesforce.com.

The following steps show how to access Salesforce.com from a PHP script and insert a new product into the Salesforce.com Product2 object.

  1. If you have not already done so, install PHP, PHP-ODBC and PHP-CLI (Command Line Interface) on your Linux / UNIX machine
  2. Install and license the Salesforce.com ODBC driver on the machine where PHP is installed.

    For installation instructions, see the Salesforce.com ODBC driver documentation. Refer to the documentation to see which environment variables you need to set (LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH or SHLIB_PATH depending on the platform and linker).

  3. Create an ODBC data source in /etc/odbc.ini that connects to your Salesforce.com organisation. For example:
    Description=Easysoft ODBC-SalesForce Driver
    Driver=Easysoft ODBC-SalesForce
  4. Use isql.sh to test the new data source. For example:
    $ cd /usr/local/easysoft/unixODBC/bin
    $ ./isql.sh -v SALESFORCE-PHP
  5. If you connection succeeds, try retrieving some Salesforce.com data. For example:
    select count(*) from Product2

    If you are unable to connect, refer to this article for assistance.

The following example PHP script inserts a product into the Salesforce.com Product2 object.


    /* ODBC connection details. Replace these values with your DSN and Salesforce.com username and password */

    /* Product details */
    $Name='Easysoft Test Product';

    /* Connect to the ODBC data source */
    if (!$conn) exit("Connection Failed:" . odbc_errormsg() );

    /* Insert the product details */
    $sql="insert into Product2 ( Name, ProductCode, Description ) "
        . "values ('".$Name."', '".$ProductCode."', '".$Description."')";

    if (!$rs) exit("Insert Failed:" . odbc_errormsg() );

    /* Get the Product2 Id from Salesforce.com to show that the insert has worked */
    $sql="select Id from Product2 where Name='".$Name."'"
    . "and ProductCode='".$ProductCode."' and Description "
    . "like '".$Description."'";
    if (!$rs) exit("Select Failed:" . odbc_errormsg() );
    $col1=odbc_result($rs, "Id");
    echo $Name." stored in Salesforce with an Id of ".$col1."\n";


To insert the new product into the Product2 object, save the PHP program to a file and then run it. For example:

$ php salesforce-product2.php
Applies To

Knowledge Base Feedback

* Did this content help you?
* Please select one option based on your first choice:

(* Required Fields)