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, there are three pieces of information required: Authentication, API URL, and WSDL URL.
Authentication
To authenticate, specify your User and Password. Note that you must append your Tenant to your User separated by an '@' character. For instance, if you normally log in with 'geraldg' and your Tenant is 'mycompany_mc1', then your User should be specified as 'geraldg@mycompany_mc1'.
API URL
The API URL may be specified either directly via APIURL, or it may be constructed from the Tenant, Service, and Host. The APIURL is constructed in the following format: <Host>/ccx/service/<Tenant>/<Service>.
WSDL URL
The WSDLURL may be specified in its entirety, or may be constructed from the Service and WSDLVersion connection properties. The WSDLURL is constructed in the following format: https://community.workday.com/sites/default/files/file-hosting/productionapi/<Service>/<WSDLVersion>/<Service>.wsdl
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.