Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Natively Connect to Zuora Data in PHP
The CData ODBC driver for Zuora enables you to create PHP applications with connectivity to Zuora data. Leverage the native support for ODBC in PHP.
Drop the CData ODBC Driver for Zuora into your LAMP or WAMP stack to build Zuora-connected Web applications. This article shows how to use PHP's ODBC built-in functions to connect to Zuora 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.
Zuora uses the OAuth standard to authenticate users. See the online Help documentation for a full OAuth authentication guide.
Configuring Tenant property
In order to create a valid connection with the provider you need to choose one of the Tenant values (USProduction by default) which matches your account configuration. The following is a list with the available options:
- USProduction: Requests sent to https://rest.zuora.com.
- USAPISandbox: Requests sent to https://rest.apisandbox.zuora.com"
- USPerformanceTest: Requests sent to https://rest.pt1.zuora.com"
- EUProduction: Requests sent to https://rest.eu.zuora.com"
- EUSandbox: Requests sent to https://rest.sandbox.eu.zuora.com"
Selecting a Zuora Service
Two Zuora services are available: Data Query and AQuA API. By default ZuoraService is set to AQuADataExport.
DataQuery
The Data Query feature enables you to export data from your Zuora tenant by performing asynchronous, read-only SQL queries. We recommend to use this service for quick lightweight SQL queries.
Limitations- The maximum number of input records per table after filters have been applied: 1,000,000
- The maximum number of output records: 100,000
- The maximum number of simultaneous queries submitted for execution per tenant: 5
- The maximum number of queued queries submitted for execution after reaching the limitation of simultaneous queries per tenant: 10
- The maximum processing time for each query in hours: 1
- The maximum size of memory allocated to each query in GB: 2
- The maximum number of indices when using Index Join, in other words, the maximum number of records being returned by the left table based on the unique value used in the WHERE clause when using Index Join: 20,000
AQuADataExport
AQuA API export is designed to export all the records for all the objects ( tables ). AQuA query jobs have the following limitations:
Limitations- If a query in an AQuA job is executed longer than 8 hours, this job will be killed automatically.
- The killed AQuA job can be retried three times before returned as failed.
Establish a Connection
Open the connection to Zuora by calling the odbc_connect or odbc_pconnect methods. To close connections, use odbc_close or odbc_close_all.
$conn = odbc_connect("CData ODBC Zuora 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 Zuora 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 Invoices WHERE BillingState = ?");
Execute Queries
Execute prepared statements with odbc_execute.
$conn = odbc_connect("CData ODBC Zuora Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Invoices WHERE BillingState = ?");
$success = odbc_execute($query, array('CA'));
Execute nonparameterized queries with odbc_exec.
$conn = odbc_connect("CData ODBC Zuora Source","user","password");
$query = odbc_exec($conn, "SELECT Id, BillingCity FROM Invoices WHERE BillingState = 'CA'");
Process Results
Access a row in the result set as an array with the odbc_fetch_array function.
$conn = odbc_connect("CData ODBC Zuora data Source","user","password");
$query = odbc_exec($conn, "SELECT Id, BillingCity FROM Invoices WHERE BillingState = 'CA'");
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 Zuora data Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Invoices WHERE BillingState = ?");
$success = odbc_execute($query, array('CA'));
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 Zuora-specific adaptations of the PHP community documentation for all ODBC functions.