Foreword
I decided to write this howto, because it took me some time to configure php to work with Sybase trying many approaches from php documentation and tutorials on the web. . What I present here is just one way of doing things, there are alternatives to that, but IMHO it's the least troublesome way (no module compiling, no strange dependencies etc.). Note that as a result you will be using sqlanywhere module for PHP by SAP company that provides compiled modules for all PHP versions > 5.1. It's not the sybase_ct module present in PHP documentation, but it provides all functionalities for interacting with the database.
Background
This tutorial has following assumptions:
- There's a need to connect to Sybase/SQL Anywhere database version 9 or above.
- The database is on a remote server.
- The connection is made from a Linux server running Apache 2+ and PHP 5.1+ using mod_php.
Following configuration was tested for RHEL Linux, but you should be able top use it on any Linux distribution. It should also be applicable to MacOS and Windows+Apache+PHP configuration.
The Steps
- Make sure you have Apache and PHP installed and configured properly.
- Download the SQL Anywhere Database Client from SQL Anywhere Database Client Download page (http://www.sybase.com/detail?id=1087327) selecting your platform.
- Unpack the archive
- From the clientxxxx directory (where xxxx is client version number) run setup script.
- You can leave all questions on their defaults (the client package will be installed in /opt/sqlanywhere12).
- Add this line to your httpd configuration script (on RHEL/CentOS/Fedora this is /etc/sysconfig/httpd).
source /opt/sqlanywhere12/bin32/sa_config.sh
It will provide proper paths to SQLAnywhere libraries. - Download appropriate compiled php module for your plaftorm and PHP version from The SAP Sybase SQL Anywhere PHP Module page (http://scn.sap.com/docs/DOC-40537).
- Copy the module to php modules directory (on RHEL/CentOS/Fedora this it's /usr/lib/php/modules, check phpinfo() output or php.ini script to see where your modules are stored.
- Add configuration entry to load the module (on RHEL/CentOS/Fedora run
echo "extension=php-5.x.x_sqlanywhere_r.so" > /etc/php.d/sqlanywhere.ini
) - Restart httpd service.
You should now be able to see the sqlanywhere section in your phpinfo() output.
Further reading
For code examples and API reference check http://dcx.sybase.com/index.html#1201/en/dbprogramming/php-support.html