Data Management

Connecting to an Actian X (Ingres) Database From PHP via JDBC

Actian Corporation

March 8, 2019

x with light behind it for actian x

We have documented the best way to connect from PHP to an Ingres database via ODBC in an Actian Knowledge Base article called Ingres ODBC with PHP and in a previous post, Connecting to Actian X (Ingres) with PHP and NGINX. Sometimes, however, due to limitations, users may need to use JDBC instead of ODBC to connect. This post shows how this can be done, although no native support exists to connect through JDBC using PHP.

In this situation a PHP-JDBC bridge is necessary. For this example, we are using the bridge available at PHP-JDBC Bridge.

Validate JDBC Connectivity

This assumes that a JDBC connection can be established. If you can run queries from a small test Java program using JDBC, then you can move to the next step.

Setup and Start the Bridge Service

Check the PHP_JDBC documentation (available at PHP-JDBC Bridge) on how to run install the necessary tools and run the service. An example of how this would run is:

java -cp “lib/pjbridge.jar:lib/commons-daemon-1.1.0.jar:$II_SYSTEM/ingres/lib/:$II_SYSTEM/ingres/lib/iijdbc.jar”
   Server com.ingres.jdbc.IngresDriver 4444 &

PHP Code Example

The following is an example of the PHP code to connect to the Ingres database:

<?php
   require "PJBridge.php"; 

   $dbHost = "localhost";
   $dbName = "testdb";
   $dbPort = "II7";
   $dbUser = "test_user";
   $dbPass = "test_password"; 

   $connStr = "jdbc:ingres://${dbHost}:${dbPort}/${dbName}"; 

   $db = new PJBridge();
   $result = $db->connect($connStr, $dbUser, $dbPass);
   if(!$result){
      die("Failed to connect");
   } 

   $cursor = $db->exec("SELECT * FROM test_table"); 

   while($row = $db->fetch_array($cursor)){
      print_r($row);
   } 

   $db->free_result($cursor);

For additional information or to arrange a demonstration please contact Professional Services at services@actian.com. You can learn more about Actian X here and visit our Actian X community forums here.

actian avatar logo

About Actian Corporation

Actian makes data easy. Our data platform simplifies how people connect, manage, and analyze data across cloud, hybrid, and on-premises environments. With decades of experience in data management and analytics, Actian delivers high-performance solutions that empower businesses to make data-driven decisions. Actian is recognized by leading analysts and has received industry awards for performance and innovation. Our teams share proven use cases at conferences (e.g., Strata Data) and contribute to open-source projects. On the Actian blog, we cover topics ranging from real-time data ingestion, data analytics, data governance, data management, data quality, data intelligence to AI-driven analytics.