![]() |
VOOZH | about |
Drop the CData ODBC Driver for Salesforce Data Cloud into your LAMP or WAMP stack to build Salesforce Data Cloud-connected Web applications. This article shows how to use PHP's ODBC built-in functions to connect to Salesforce Data Cloud data, execute queries, and output the results.
If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.
Salesforce Data Cloud supports authentication via the OAuth standard.
Set to OAuth.
CData provides an embedded OAuth application that simplifies authentication at the desktop.
You can also authenticate from the desktop via a custom OAuth application, which you configure and register at the Salesforce Data Cloud console. For further information, see Creating a Custom OAuth App in the Help documentation.
Before you connect, set these properties:
When you connect, the driver opens Salesforce Data Cloud's OAuth endpoint in your default browser. Log in and grant permissions to the application.
The driver then completes the OAuth process as follows:
For other OAuth methods, including Web Applications and Headless Machines, refer to the Help documentation.
Open the connection to Salesforce Data Cloud by calling the or methods. To close connections, use or .
$conn = odbc_connect("CData ODBC SalesforceDataCloud Source","user","password");
Connections opened with are closed when the script ends. Connections opened with the method are still open after the script ends. This enables other scripts to share that connection when they connect with the same credentials. By sharing connections among your scripts, you can save system resources, and queries execute faster.
$conn = odbc_pconnect("CData ODBC SalesforceDataCloud Source","user","password");
...
odbc_close($conn); //persistent connection must be closed explicitly
Create prepared statements and parameterized queries with the function.
$query = odbc_prepare($conn, "SELECT * FROM Account WHERE EmployeeCount = ?");
Execute prepared statements with .
$conn = odbc_connect("CData ODBC SalesforceDataCloud Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Account WHERE EmployeeCount = ?");
$success = odbc_execute($query, array('250'));
Execute nonparameterized queries with .
$conn = odbc_connect("CData ODBC SalesforceDataCloud Source","user","password");
$query = odbc_exec($conn, "SELECT [Account ID], [Account Name] FROM Account WHERE EmployeeCount > 250");
Access a row in the result set as an array with the function.
$conn = odbc_connect("CData ODBC Salesforce Data Cloud data Source","user","password");
$query = odbc_exec($conn, "SELECT [Account ID], [Account Name] FROM Account WHERE EmployeeCount > 250");
while($row = odbc_fetch_array($query)){
echo $row["[Account ID]"] . "\n";
}
Display the result set in an HTML table with the function.
$conn = odbc_connect("CData ODBC Salesforce Data Cloud data Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Account WHERE EmployeeCount = ?");
$success = odbc_execute($query, array('250'));
if($success)
odbc_result_all($query);
You will find complete information on the driver's supported SQL in the help documentation. The code examples above are Salesforce Data Cloud-specific adaptations of the PHP community documentation for all ODBC functions.
Download a free trial of the Salesforce Data Cloud ODBC Driver to get started:
Download NowLearn more:
👁 Salesforce Data Cloud IconThe Salesforce Data Cloud ODBC Driver is a powerful tool that allows you to connect with live data from Salesforce Data Cloud, directly from any applications that support ODBC connectivity.
Access Salesforce Data Cloud data like you would a database - read, write, and update Salesforce Data Cloud 0, etc. through a standard ODBC Driver interface.