Ready to get started?

Learn more about the CData ODBC Driver for HPCC or download a free trial:

Download Now

Natively Connect to HPCC Systems Data in PHP

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

Drop the CData ODBC Driver for HPCC Systems into your LAMP or WAMP stack to build HPCC Systems-connected Web applications. This article shows how to use PHP's ODBC built-in functions to connect to HPCC Systems 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, set the following connection properties: Set URL to the machine name or IP address of the server and the port the server is running on, for example, https://server:port. The User and Password are required to authenticate to the HPCC Systems cluster specified in the URL. Note that LDAP authentication is not currently supported by our ODBC driver.

Set Version to the WsSQL Web server version. Note that if you have not already done so, you will need to install the WsSQL service on the HPCC Systems server. The WsSQL Web service is used to interact with the underlying HPCC Systems platform.

Set Cluster to the target cluster.

Establish a Connection

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

$conn = odbc_connect("CData ODBC HPCC 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 HPCC 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 hpcc::test::orders WHERE ShipCity = ?");

Execute Queries

Execute prepared statements with odbc_execute.

$conn = odbc_connect("CData ODBC HPCC Source","user","password"); $query = odbc_prepare($conn, "SELECT * FROM hpcc::test::orders WHERE ShipCity = ?"); $success = odbc_execute($query, array('New York'));

Execute nonparameterized queries with odbc_exec.

$conn = odbc_connect("CData ODBC HPCC Source","user","password"); $query = odbc_exec($conn, "SELECT SUM(hpcc::test::orders.Price), hpcc::test::customers.CustomerName FROM hpcc::test::orders INNER JOIN hpcc::test::customers ON hpcc::test::orders.CustomerId=hpcc::test::customers.CustomerId;GROUP BY hpcc::test::customers.CustomerName");

Process Results

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

$conn = odbc_connect("CData ODBC HPCC Systems data Source","user","password"); $query = odbc_exec($conn, "SELECT SUM(hpcc::test::orders.Price), hpcc::test::customers.CustomerName FROM hpcc::test::orders INNER JOIN hpcc::test::customers ON hpcc::test::orders.CustomerId=hpcc::test::customers.CustomerId;GROUP BY hpcc::test::customers.CustomerName"); while($row = odbc_fetch_array($query)){ echo $row["CustomerName"] . "\n"; }

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

$conn = odbc_connect("CData ODBC HPCC Systems data Source","user","password"); $query = odbc_prepare($conn, "SELECT * FROM hpcc::test::orders WHERE ShipCity = ?"); $success = odbc_execute($query, array('New York')); 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 HPCC Systems-specific adaptations of the PHP community documentation for all ODBC functions.