Connecting to an Ingres database with PHP

Last update on October 8, 2009 10:43 AM by jak58
Published by netty5

Connecting to an Ingres database with PHP








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) http://pecl4win.php.net/ext.php/php_ingres.dll
Linux & Unix (code source) http://pecl.php.net/package/ingres

Installation


Windows


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.
echo $II_SYSTEM


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


phpize 
  • Build the Makefile:

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


make 
  • Install the extension:


make install


Edit php.ini and add the following line extension = ingres.so
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/mod_env.so
SetEnv II_SYSTEM votre-répertoire-II_SYSTEM
SetEnv LD_LIBRARY_PATH votre-répertoire-II_SYSTEM/ingres/lib

Getting connected

  • Getting connected

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

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

<?php
$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

<?php
$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

<?php
// Fetch the image to be inserted
$handle = fopen (“usrname.png”,”r”);
$login_image = stream_get_contents($handle);
fclose($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);
?>
Best answers for « Connecting to an Ingres database with PHP » in :
Connect a database (MDB) to excel Show [VBA] Connecting a database (MDB) to excel Below is a tips of how to connect an Access database (MDB) in an application excel Add reference Microsoft DAO object librairy X.X In a general module (eg Module1) paste the code below...
Connecting to Oracle via php ShowConnecting to Oracle via php Settings Requirements Example of code Settings Below is an article based on an example of connection to an Oracle database through a php script. However it is not designed to configure your oracle...
Official Ingres documentation ShowOfficial Ingres documentation Download Notice Download You can download all documentation of Ingres on below link: http://www.ingres.com/downloads/prod-download-documents.php The list (not exhaustive) guides...
Creating database under Ingres ShowCreating database under Ingres Intro Example createdb Intro Ingres is a relational database management system (RDBMS) that is based upon a research project from the University of California at Berkeley . There are two different...
Download Aqua Data Studio ShowAqua Data Studio is an advanced SQL editor. It can create, edit and execute SQL scripts. This software provides an integrated database with only one interface for connecting to databases. Query Analyzer enables users to work on RDBMS synthax and auto...
ODBC ShowWhat is ODBC? ODBC stands for Open Database Connectivity. This is a Microsoft-defined format for communicating between Windows database clients and consumer DBMSs. The ODBC managier can be found in Windows 3.1 and 9x. In Windows 95 and 98, it is...
Databases - Using forms ShowUsing forms In order to use databases, the user must be provided with an interface that allows him or her to view data based on certain criteria. There is a tool for this: forms. A form is an interface with components for displaying, entering, or...
Sharing an Internet connection ShowAdvantages If you have a local area network (two or more computers connected in a network) with one computer connected to the Internet (via a modem, using a cable, etc.), it may be useful to make the connection accessible to the other computers on...