1. PHP Interface#
This chapter explains how to integrate PHP pages with Altibase using PHP's ODBC functionality.
About the PHP Module of Altibase#
- The following data types are supported for use with Altibase and PHP:
resource, int, bool, double, float, string, array, HashTable - The port number in db.php, the sample program, must be changed so that it matches the port number that is actually being used on the Altibase server.
Installing the ODBC Manager for Integration with PHP#
In order to integrate Altibase with the PHP interface, the ODBC Manager must be installed. This section describes how to install the ODBC Manager in Unix, or Linux environments.
The ODBC Manager in Unix and Linux#
In a Unix or Linux environment, complete the following steps to install the ODBC Manager:
-
Download unixODBC.
It can be downloaded from the unixODBC website. -
Install unixODBC.
After downloading the unixODBC source files, it is necessary to compile unixODBC. Move the source files to the desired location and run the following commands from a command prompt:./configure -prefix=installation_path -enable-gui=no -–enable-drivers=no make make install
-
Configure the unixODBC environment.
A. Set the value of the ODBCSYSINI environment variable to the home directory path of the Altibase installation account.
export ODBCSYSINI=~
-
Add an environment variable indicating the path where the unixODBC Driver Manager is installed, as shown below. Depending on the platform and whether the OS is a 32-bit or 64-bit OS, the library path will be one of LD_LIBRARY_PATH, LD_LIBRARY_PATH_64 or SHLIB_PATH.
In the following example, unixODBC is installed at /usr/local/odbcDriverManager32 or /usr/local/odbcDriverManager64.
export LD_LIBRARY_PATH= /usr/local/odbcDriverManager32/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH_64= /usr/local/odbcDriverManager64/lib:$LD_LIBRARY_PATH_64
-
Create the following two files in the $ODBCSYSINI path:
odbc.ini odbcinst.ini
-
odbcinst.ini must be an empty file having a size of 0 bytes.
-
In odbc.ini, specify the DSN name, the path and directory where the ODBC driver of Altibase is installed, and the server address and port number.
[Altibase] Driver = /home/altibase/altibase_home/lib/libaltibase_odbc.so Server = 127.0.0.1 Port = 20300
PHP Functions for ODBC Connectivity#
Altibase supports all standard ODBC functions, and thus all ODBC functions that are typically used in PHP pages can be used with Altibase without any special considerations.
For a detailed explanation of the ODBC functions that can be used with PHP, please refer to the official PHP online documentation.
Sample Test#
<?
// SYSTEM DSN, USER_ID, USER_PASSWORD
$conn = odbc_connect("Altibase", "SYS", "MANAGER");
if ($conn)
{
// direct-execution
echo "now, i create table t1 (id integer, name char(20)<br>";
odbc_exec($conn, "drop table t1");
odbc_exec($conn, "create table t1 (id integer, name char(20))");
// prepare-execution
echo "now, i insert into t1 value (100, Lee)<br>";
$stmt = odbc_prepare ($conn, "insert into t1 values (?, ?)");
$Insert = array (100, "Lee");
if (!odbc_execute($stmt, &$Insert))
{
echo ("error");
}
// single-selection
$res = odbc_do ($conn, "select id, name, sysdate from T1");
odbc_fetch_row ($res);
$ID = odbc_result($res, 1);
$NAME = odbc_result($res, 2);
$DATE = odbc_result($res, 3);
echo ("id = $ID , name = $NAME datetime = $DATE <br>");
odbc_close($conn);
}
?>