Connecting to an Ingres database with PHP

May 2017

This tip is based on following Ingres documentation:

Getting started

Ingres® 2006 Release 2 for Windows Quick Start Guide (qs_windows.pdf)
Ingres® 2006 Release 2 for Linux Quick Start Guide (qs_linux.pdf)

Download PECL

Windows (driver)
Linux & Unix (code source)



Copy the file php_ingres.dll in the directory of PHP extensions.
Edit your php.ini and add the following line:
extension = php_ingres.dll 

Linux & Unix

Locate the directory where the command phpize or php-config lies.
On some Linux distributions it is necessary to rename these files to avoid conflicts.
To compile the Ingres PECL library you need a compiler.
Make sure that the variable II_SYSTEM is valued.

Move to the directory containing the source code for the extension :
  • Generate configuration for the extension:

  • Build the Makefile:

./configure --with-ingres
  • Compile the extension:

  • Install the extension:

make install

Edit php.ini and add the following line extension =
If you use Apache, use the directive users of httpd.conf
to make sure that Apache will run well with a valid Ingres user

Apache for Linux & Unix

In the Apache configuration, add the following lines

LoadModule env_module modules/
SetEnv II_SYSTEM votre-répertoire-II_SYSTEM
SetEnv LD_LIBRARY_PATH votre-répertoire-II_SYSTEM/ingres/lib

Getting connected

  • Getting connected

$link = ingres_connect(“mydb”, “username”, “password”);
or die(“Could not connect”);
echo “Connected successfully”;
  • Error test

$link = ingres_connect(“mydb”, “username”, “password”);
if (ingres_errno($link) != 0) {
echo ingres_errno($link) . “ : “ . ingres_error($link) . “<BR/>\n”;
  • Simple request

$link = ingres_connect(“mydb”, “username”, “password”);
// Gives a list of the tables
$sql = “select * from iirelation order by relid asc”;
$rc = ingres_query($sql,$link);
// Do some error checking...
while ( $iirelation = ingres_fetch_object($link) ) {
echo $iirelation->relid “<BR/>\n”;
  • Make a request with parameters

$link = ingres_connect(“iidbdb”, “ingres”, “ingres”);
// Gives a list of the tables based on a parameter
$sql = “select * from iirelation where relowner = ? order by relid asc”;
$params[“owner1”] = (“usrname”);
$rc = ingres_query($sql,$link,$params);
// Do some error checking...
while ( $iirelation=ingres_fetch_object($link) ) {
echo $iirelation->relid “<BR/>\n”;
  • Loading a BLOB

// Fetch the image to be inserted
$handle = fopen (“usrname.png”,”r”);
$login_image = stream_get_contents($handle);
// Set up the query
$sql = “insert into login_images values (?,?)”;
// Type the parameters being passed
$types = “vB”; // varchar, BLOB
// Set up the parameter values
$params[“login”] = “usrname”;
$params[“image”] = $login_image;
// Execute
$rc = ingres_query($sql,$link,$params,$types);


Published by netty5. Latest update on November 29, 2009 at 07:18 AM by aquarelle.
This document, titled "Connecting to an Ingres database with PHP," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (