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.
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).
[SALESFORCE-PHP] Description=Easysoft ODBC-SalesForce Driver Driver=Easysoft ODBC-SalesForce uri=https://login.salesforce.com/services/Soap/u/27 user=myuser@mydomain.com password=p455w0rd token=aBCdEfG1hij2kLmNoPq3R4STu
$ cd /usr/local/easysoft/unixODBC/bin $ ./isql.sh -v SALESFORCE-PHP
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.
<?php /* ODBC connection details. Replace these values with your DSN and Salesforce username and password */ $ODBC_Connection='SALESFORCE-PHP'; $ODBC_User='myuser@mydomain.com'; $ODBC_Pass='p455w0rd'; /* Product details */ $Name='Easysoft Test Product'; $ProductCode='ETP001'; $Description='12345-67890'; /* Connect to the ODBC data source */ $conn=odbc_connect($ODBC_Connection,$ODBC_User,$ODBC_Pass); if (!$conn) exit("Connection Failed:" . odbc_errormsg() ); /* Insert the product details */ $sql="insert into Product2 ( Name, ProductCode, Description ) " . "values ('".$Name."', '".$ProductCode."', '".$Description."')"; $rs=odbc_exec($conn,$sql); 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."'"; $rs=odbc_exec($conn,$sql); if (!$rs) exit("Select Failed:" . odbc_errormsg() ); odbc_fetch_row($rs); $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