User Contributed Notes 25 notes

Poor documentation on sybase support!! Here's how I made it work... First get the linux ASE from sybase (maybe the ctlibs provided at php.net will do fine, too) Install the ASE rpm. (some distributions don't have system libs etc in the rpm database so you might get some dependency errors. If your systems fits the requirements install with "ignore dependencies") Recompile php with option --with-sybase-ct=/dirtoyoursybasehome. Then you need to set the env variable for (at least)your apache user by export SYBASE=/dirtoyoursybasehome. Now you need to set up your servers (like DSNs for ODBC). Edit the file $SYBASE/interfaces and add your server entries:

(change IP/FQHN and port to your setup) Now you can check your config by using
$SYBASE/bin/isql -S SERVERNAME -U DBUSER -P PASSWD
If you get a prompt you have connected to your sybase! Hurray! Now you can try with php
$db=sybase_connect("SERVERNAME","DBUSER","DBPASSWD");
And... Voila!

For ASE 15 you can run $SYBASE/$SYBASE_OCS/scripts/lnsyblibs to create symlinks for the older library names. Using this instead of cp will presumably not break your installation should you apply something like an EBF.

Ensure you have an 'interfaces' file in the root of your sybase distribution (Above the OCS-12_5 subdirectory), containing a server entry in the following format for each server you want to connect to:

(if this is your dataserver machine, there will be at least 1 entry already for the local dataserver. It is advisable to install all of the above on a separate machine though, with its own copy of the sybase client)

Cross fingers, and:

apachectl start

If you get 'relocation' errors when starting Apache with the php module configured to load, check the output of 'ldd libphp5.so'. Each of the Sybase libraries should link to files under your Sybase client distribution:

If you see 'libintl.so' linking anywhere else, this is likely because the PHP build has incorrectly linked to a slightly different filename - libintl.so.1 - which doesn't exist in the Sybase client. Unfortunately a completely unrelated library of the same name does exist elsewhere in Unix! (Apparently the Sybase version was created before the duplicate was introduced into Unix).

My workaround was to create the following symlink in sybase client library 'lib' directory -

libintl.so.1 -> ./libintl.so*

'make distclean' in your PHP build directory, and repeat the build as above.

In response to the post by jon dot bertsch at ucop dot edu, it is possible to install both the FreeTDS libraries and the Sybase libraries. The problem is that the Sybase extension alias's its function names to the mssql_ functions.

Take a look in your PHP source directory under /ext/sybase_ct/php_sybase_ct.c near the top where the sybase_functions[] declaration is. You can comment out the part that alias's the function names, recompile with FreeTDS and Sybase, and you're all set!

Up to php 5.0.4 you cannot install both sybase and mssql (they use the same function names). It turns out though that if you use the Freetds library you can connect to sybase using the mssql functions (and visa versa I assume). Setup your servers in the freetds.conf file (for sybase use specify version 5.0, for mssql 7 or 8.0) and call the database connection as you would with mssql (mssql_conect). You should be able to connect either sql server or sybase. I don't know if all sybase functions will work as expected but basic querying is succesful. Hope this helps someone.

I've noticed (after days of frustration) that setting the sybase.interface_file to a location other than the default ($SYBASE/interfaces) in php.ini doesn't always work. I finally gave up and copied my interface entries to the default location, and it works consistently now. (This is even with sybase.interface_file still set to the non-default location).

There is a way how to force php work with both php_mssql.dll and php_sybase_ct.dll. Just open php_sybase_ct.dll in any editor (dont use MS WORD :0) ) and replace all "mssql_" on something like that "masql_".After that there will not be warnings about double function definitions and php can use php_sybase_ct.dll to access to sybase and php_mssql.dll to access to mssql.The reason why I did such thing is that I couldnt connect to mssql using php_sybase_ct.dll.

If you would like to use the wide table support of Sybase ASE 12.5, take advantage of XML/XQL embedded in the database and use varchars of more than 255 char, you'll need to recompile PHP changing this line in the php_sybase_ct.h file:

From:

#define CTLIB_VERSION CS_VERSION_100

To:

#define CTLIB_VERSION CS_VERSION_125

This will only run if you have installed Sybase ASE Open Client v. 12.5 and configured PHP telling it where the OCS is... (./configure --with-sybase-ct=$SYBASE_HOME/OCS [...])

For those who use Freetds 5.2 running under linux connect to sqlserver2000, there is a bugs in selecting NVARCHAR field that data will either duplicated or truncated. To avoid this problem, please use CAST or CONVERT function in sql statement such as:$query="select CAST(fieldname as nchar(1000)) as fieldname from table"

I would STRONGLY recommend using the ct library over the db library when compiling sybase support with php4+. I ran into strange http child seg faults when trying to issue multiple sql statements in one php page. Using ct-library there is no problem.

I struggled to get this to work for a week. Here's a tip. Log on to your system using the same login as your web server, probably "nobody". Using this account, make sure you can get isql to work. In my case, I had to change the permissions on the /opt/sybase folder, as well as chmod the /opt/sybase/interfaces file to 644. (It was 600 by default, and did not allow anyone but root to read it.) Once I did this, things started to happen...

ASA can work with TDS (Open Client), but if performance is something you care about you likely want to use the native ASA interface. For info/help, consider posting to sybase.public.sqlanywhere.general or sybase.public.sqlanywhere.linux (http://www.ianywhere.com/support/newsgroups.html)