Natively Connect to Cvent Data in PHP



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

Drop the CData ODBC Driver for Cvent into your LAMP or WAMP stack to build Cvent-connected Web applications. This article shows how to use PHP's ODBC built-in functions to connect to Cvent 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.

Before you can authenticate to Cvent, you must create a workspace and an OAuth application.

Creating a Workspace

To create a workspace:

  1. Sign into Cvent and navigate to App Switcher (the blue button in the upper right corner of the page) >> Admin.
  2. In the Admin menu, navigate to Integrations >> REST API.
  3. A new tab launches for Developer Management. Click on Manage API Access in the new tab.
  4. Create a Workspace and name it. Select the scopes you would like your developers to have access to. Scopes control what data domains the developer can access.
    • Choose All to allow developers to choose any scope, and any future scopes added to the REST API.
    • Choose Custom to limit the scopes developers can choose for their OAuth apps to selected scopes. To access all tables exposed by the driver, you need to set the following scopes:
      event/attendees:readevent/attendees:writeevent/contacts:read
      event/contacts:writeevent/custom-fields:readevent/custom-fields:write
      event/events:readevent/events:writeevent/sessions:delete
      event/sessions:readevent/sessions:writeevent/speakers:delete
      event/speakers:readevent/speakers:writebudget/budget-items:read
      budget/budget-items:writeexhibitor/exhibitors:readexhibitor/exhibitors:write
      survey/surveys:readsurvey/surveys:write

Creating an OAuth Application

After you have set up a Workspace and invited them, developers can sign up and create a custom OAuth app. See the Creating a Custom OAuth Application section in the Help documentation for more information.

Connecting to Cvent

After creating an OAuth application, set the following connection properties to connect to Cvent:

  • InitiateOAuth: GETANDREFRESH. Used to automatically get and refresh the OAuthAccessToken.
  • OAuthClientId: The Client ID associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.
  • OAuthClientSecret: The Client secret associated with the OAuth application. You can find this on the Applications page in the Cvent Developer Portal.

Establish a Connection

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

$conn = odbc_connect("CData ODBC Cvent 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 Cvent 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 Events WHERE Virtual = ?");

Execute Queries

Execute prepared statements with odbc_execute.

$conn = odbc_connect("CData ODBC Cvent Source","user","password"); $query = odbc_prepare($conn, "SELECT * FROM Events WHERE Virtual = ?"); $success = odbc_execute($query, array('true'));

Execute nonparameterized queries with odbc_exec.

$conn = odbc_connect("CData ODBC Cvent Source","user","password"); $query = odbc_exec($conn, "SELECT Id, Title FROM Events WHERE Virtual = 'true'");

Process Results

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

$conn = odbc_connect("CData ODBC Cvent data Source","user","password"); $query = odbc_exec($conn, "SELECT Id, Title FROM Events WHERE Virtual = 'true'"); 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 Cvent data Source","user","password"); $query = odbc_prepare($conn, "SELECT * FROM Events WHERE Virtual = ?"); $success = odbc_execute($query, array('true')); 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 Cvent-specific adaptations of the PHP community documentation for all ODBC functions.

Ready to get started?

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

 Download Now

Learn more:

Cvent Icon Cvent ODBC Driver

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

Access Cvent data like you would a database - read, write, and update Cvent 0, etc. through a standard ODBC Driver interface.