Natively Connect to Adobe Target Data in PHP



The CData ODBC driver for Adobe Target enables you to create PHP applications with connectivity to Adobe Target data. Leverage the native support for ODBC in PHP.

Drop the CData ODBC Driver for Adobe Target into your LAMP or WAMP stack to build Adobe Target-connected Web applications. This article shows how to use PHP's ODBC built-in functions to connect to Adobe Target data, execute queries, and output the results.

Configure a DSN

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.

To connect to Adobe Target, you must provide the Tenant property along with OAuth connection properties mentioned below. Note that while other connection properties can influence processing behavior, they do not affect the ability to connect.

To determine your Tenant name:

  1. Log in to Adobe Experience. The URL will look similar to: "https://experience.adobe.com/#/@mycompanyname/preferences/general-section".
  2. Extract the value after the "/#/@". In this example, it is "mycompanyname".
  3. Set the Tenant connection property to that value.

User Accounts (OAuth)

You must set AuthScheme to OAuthClient for all user account flows.

Note: Adobe authentication via OAuth requires updating your token every two weeks.

All Applications

CData provides an embedded OAuth application that simplifies OAuth authentication. Alternatively, you can create a custom OAuth application. Review Creating a Custom OAuth App in the Help documentation for more information.

Obtaining the OAuth Access Token

Set the following properties to connect:

  • InitiateOAuth: Set to GETANDREFRESH to automatically perform the OAuth exchange and refresh the OAuthAccessToken as needed.
  • OAuthClientId : Set to the client Id assigned when you registered your app.
  • OAuthClientSecret : Set to the client secret assigned when you registered your app.
  • CallbackURL : Set to the redirect URI defined when you registered your app. For example: https://localhost:3333

With these settings, the provider obtains an access token from Adobe Target, which it uses to request data. The OAuth values are stored in the location specified by OAuthSettingsLocation, ensuring they persist across connections.

Establish a Connection

Open the connection to Adobe Target by calling the odbc_connect or odbc_pconnect methods. To close connections, use odbc_close or odbc_close_all.

$conn = odbc_connect("CData ODBC AdobeTarget Source","user","password");

Connections opened with odbc_connect are closed when the script ends. Connections opened with the odbc_pconnect 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 AdobeTarget Source","user","password");
...
odbc_close($conn); //persistent connection must be closed explicitly

Create Prepared Statements

Create prepared statements and parameterized queries with the odbc_prepare function.

$query = odbc_prepare($conn, "SELECT * FROM Activities WHERE Type = ?");

Execute Queries

Execute prepared statements with odbc_execute.

$conn = odbc_connect("CData ODBC AdobeTarget Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Activities WHERE Type = ?");
$success = odbc_execute($query, array('AB'));
  

Execute nonparameterized queries with odbc_exec.

$conn = odbc_connect("CData ODBC AdobeTarget Source","user","password");
$query = odbc_exec($conn, "SELECT Id, Name FROM Activities WHERE Type = 'AB'");
  

Process Results

Access a row in the result set as an array with the odbc_fetch_array function.

$conn = odbc_connect("CData ODBC Adobe Target data Source","user","password");
$query = odbc_exec($conn, "SELECT Id, Name FROM Activities WHERE Type = 'AB'");
while($row = odbc_fetch_array($query)){
 echo $row["Id"] . "\n";
}

Display the result set in an HTML table with the odbc_result_all function.

$conn = odbc_connect("CData ODBC Adobe Target data Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Activities WHERE Type = ?");
$success = odbc_execute($query, array('AB'));
if($success)
  odbc_result_all($query);

More Example Queries

You will find complete information on the driver's supported SQL in the help documentation. The code examples above are Adobe Target-specific adaptations of the PHP community documentation for all ODBC functions.

Ready to get started?

Download a free trial of the Adobe Target ODBC Driver to get started:

 Download Now

Learn more:

Adobe Target Icon Adobe Target ODBC Driver

The Adobe Target ODBC Driver is a powerful tool that allows you to connect with live data from live Adobe Target, directly from any applications that support ODBC connectivity.

Read, write, and update online sheets through a standard ODBC interface.