PHP Integration Guide for Altibase#
Overview#
This chapter describes how to integrate with Altibase using the ODBC functions in PHP.
Info
For errors and improvements related to this document, please contact the technical support portal or technical support center.
- Technical support portal: http://support.altibase.com/en
- Technical support center: +82-2-2082-1114
Info
This document is provided for informational purposes only and is subject to change without prior notice. It may contain errors, and Altibase makes no express or implied warranties of any kind, including but not limited to warranties of merchantability or fitness for a particular purpose.
The development, release, and timing of any features or functionality described for Altibase products in this document are at the sole discretion of Altibase.
Altibase may hold patents, trademarks, copyrights, or other intellectual property rights related to the contents of this document.
Altibase PHP Module Reference#
The data types supported by PHP are as follows:
resource, int, bool, double, float, string, array, HashTable
The port number of the Altibase server and the port number in db.php of the sample program provided by Altibase must be matched.
ODBC Manager Installation for PHP Integration#
To integrate Altibase with PHP in Unix or Windows environment, the ODBC manager must be installed first.
This section describes how to install the ODBC manager and configure the environment for Unix, Linux, and Windows.
Unix and Linux#
Install the ODBC manager in the Linux or Unix environment using the following procedure.
-
Download unixODBC.
This can be downloaded from the unixODBC website (http://www.unixodbc.org). -
Install unixODBC.
The user needs to compile the downloaded unixODBC source file. To install the compiled library in a specific location, enter the path with the -prefix option when configuring../configure -prefix=Installation path -enable-gui=no -–enable-drivers=no make make install -
Configure the unixODBC environment.
Set the value of the ODBCSYSINI environment variable to the home directory path of the Altibase installation account.export ODBCSYSINI=~ -
Add the path where the unixODBC Driver Manager is installed to the environment variable as follows.
The environment variable for setting the library path may be one of LD_LIBRARY_PATH, LD_LIBRARY_PATH_64, and SHLIB_PATH depending on the platform and operating system bit.
The following is an example of installing unixODBC in /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 2 files in the path of the ODBCSYSINI environment variable.
odbc.ini odbcinst.ini -
odbcinst.ini is a 0-byte file with no actual contents.
-
In odbc.ini, set the DSN name, the location of the Altibase ODBC driver file, the server's IP address, and the connection port number as follows.
[Altibase] Driver = /home/altibase/altibase_home/lib/libaltibase_odbc.so Server = 127.0.0.1 Port = 20300
Windows#
In the Windows environment, the ODBC manager is installed by default. When Altibase is installed, the Altibase ODBC driver is automatically registered in the ODBC manager.
PHP Functions for ODBC Connection#
Altibase supports standard ODBC, so you can use these ODBC functions in PHP to interface with the Altibase server.
For a detailed description of the ODBC functions used in PHP, refer to the PHP official manual site below:
https://www.php.net/manual/en/book.uodbc.php
Sample Test#
<?php
// SYSTEM DSN, USER_ID, USER_PASSWORD
$conn = odbc_connect('TESTDSN', 'SYS', 'MANAGER');
if ($conn) {
// direct-execution
echo "now, i create table t1 (id integer, name char(20)";
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)";
$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 ");
odbc_close ( $conn );
}
else
{
echo "connection failed ...";
}
?>