Easysoft ODBC-Salesforce Driver

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

Last Reviewed:
30th January 2024

Use the Salesforce ODBC Driver to connect PHP to Salesforce.

The following steps show how to access Salesforce from a PHP script and insert a new product into the Salesforce 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 ODBC driver on the machine where PHP is installed.

    For installation instructions, see the Salesforce 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 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 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 Product2 object.


    /* ODBC connection details. Replace these values with your DSN and Salesforce 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 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)