Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Natively Connect to Workday Data in PHP
The CData ODBC driver for Workday enables you to create PHP applications with connectivity to Workday data. Leverage the native support for ODBC in PHP.
Drop the CData ODBC Driver for Workday into your LAMP or WAMP stack to build Workday-connected Web applications. This article shows how to use PHP's ODBC built-in functions to connect to Workday 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 Workday, users need to find the Tenant and BaseURL and then select their API type.
Obtaining the BaseURL and Tenant
To obtain the BaseURL and Tenant properties, log into Workday and search for "View API Clients." On this screen, you'll find the Workday REST API Endpoint, a URL that includes both the BaseURL and Tenant.
The format of the REST API Endpoint is: https://domain.com/subdirectories/mycompany, where:
- https://domain.com/subdirectories/ is the BaseURL.
- mycompany (the portion of the url after the very last slash) is the Tenant.
Using ConnectionType to Select the API
The value you use for the ConnectionType property determines which Workday API you use. See our Community Article for more information on Workday connectivity options and best practices.
API | ConnectionType Value |
---|---|
WQL | WQL |
Reports as a Service | Reports |
REST | REST |
SOAP | SOAP |
Authentication
Your method of authentication depends on which API you are using.
- WQL, Reports as a Service, REST: Use OAuth authentication.
- SOAP: Use Basic or OAuth authentication.
See the Help documentation for more information on configuring OAuth with Workday.
Establish a Connection
Open the connection to Workday by calling the odbc_connect or odbc_pconnect methods. To close connections, use odbc_close or odbc_close_all.
$conn = odbc_connect("CData ODBC Workday 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 Workday 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 Workers WHERE Legal_Name_Last_Name = ?");
Execute Queries
Execute prepared statements with odbc_execute.
$conn = odbc_connect("CData ODBC Workday Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Workers WHERE Legal_Name_Last_Name = ?");
$success = odbc_execute($query, array('Morgan'));
Execute nonparameterized queries with odbc_exec.
$conn = odbc_connect("CData ODBC Workday Source","user","password");
$query = odbc_exec($conn, "SELECT Worker_Reference_WID, Legal_Name_Last_Name FROM Workers WHERE Legal_Name_Last_Name = 'Morgan'");
Process Results
Access a row in the result set as an array with the odbc_fetch_array function.
$conn = odbc_connect("CData ODBC Workday data Source","user","password");
$query = odbc_exec($conn, "SELECT Worker_Reference_WID, Legal_Name_Last_Name FROM Workers WHERE Legal_Name_Last_Name = 'Morgan'");
while($row = odbc_fetch_array($query)){
echo $row["Worker_Reference_WID"] . "\n";
}
Display the result set in an HTML table with the odbc_result_all function.
$conn = odbc_connect("CData ODBC Workday data Source","user","password");
$query = odbc_prepare($conn, "SELECT * FROM Workers WHERE Legal_Name_Last_Name = ?");
$success = odbc_execute($query, array('Morgan'));
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 Workday-specific adaptations of the PHP community documentation for all ODBC functions.