6/20/2012

Connecting Sybase with PHP

Firstly ensure you installed PHP with Sybase with ./configure.

./configure --prefix=/apps/solace/php --with-apxs2=/apps/solace/apache/bin/apxs --with-libxml-dir=/home/tptools/Linux/x86_64 --with-png-dir=/home/tptools/Linux/x86_64 --enable-bcmath --enable-mbstring --enable-sockets --with-mysql=/home/tptools/Linux/x86_64/vendor/mysql-5.1.36-linux-x86_64-glibc23 --with-sybase-ct=$SYBASE/version#

the SYBASE variable should set to the home dir of sybase. And the hostname will be in the sybase interfaces file.

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc35823_1500/html/uconfig/X41537.htm

Here is some sample code to setup connection with Sybase:
<?php 
$conn=sybase_connect('DATABASE_NAME','USERNAME','PASSCODE')
or die('Could not connect: ' . mysql_error());

if (!sybase_select_db('SUB_DATABASE',$conn)) {
echo "Can't select database\n";
exit;
}
echo "Connected!";
sybase_close($conn);
?>


And if you see the message Could not connect: It is the parameter you set for the connection incorrect.

Or you haven't setup your local tomcat environment file in apache's bin directory envvars file.
Add 
SYBASE=/usr/local/sybase
export SYBASE

and start tomcat again with apachectl start. you will be fine.
If you don't like the warnings popping up, go to the php.ini file (which should be in your php's lib dir, or try phpinfo() to see where the ini file is) and change the warning settings.


Don't forget to setup the root environment variables:

setenv SYB_USER username
setenv SYB_PASSWD password

1 comment: