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.
CLVI. Sybase 関数
インストール手順
Sybase-DB サポートを有効にするには、PHP の configure で --with-sybase[=DIR] を指定して ください。DIR は Sybase のホームディレクトリで、デフォルトは /home/sybase です。 Sybase-CT サポートを有効にするには、PHP の configure で --with-sybase-ct[=DIR] を指定して ください。DIR は Sybase のホームディレクトリで、デフォルトは /home/sybase です。
実行時設定
php.ini の設定により動作が変化します。
表 1. Sybase 設定オプション
| 名前 | デフォルト | 変更の可否 | 変更履歴 |
|---|---|---|---|
| sybase.allow_persistent | "1" | PHP_INI_ALL | PHP <= 4.0.2 では PHP_INI_ALL、PHP <= 4.0.3 では PHP_INI_SYSTEM。 |
| sybase.max_persistent | "-1" | PHP_INI_ALL | PHP <= 4.0.2 では PHP_INI_ALL、PHP <= 4.0.3 では PHP_INI_SYSTEM。 |
| sybase.max_links | "-1" | PHP_INI_ALL | PHP <= 4.0.2 では PHP_INI_ALL、PHP <= 4.0.3 では PHP_INI_SYSTEM。 |
| sybase.interface_file | "/usr/sybase/interfaces" | PHP_INI_SYSTEM | |
| sybase.min_error_severity | "10" | PHP_INI_ALL | |
| sybase.min_message_severity | "10" | PHP_INI_ALL | |
| sybase.compatability_mode | "0" | PHP_INI_ALL | |
| magic_quotes_sybase | "0" | PHP_INI_ALL |
以下に設定ディレクティブに関する 簡単な説明を示します。
- sybase.allow_persistent boolean
持続的な Sybase 接続を使用可能とするかどうか。
- sybase.max_persistent integer
プロセス毎の持続的な Sybase 接続の最大数。-1 は制限無しを意味します。
- sybase.max_links integer
プロセス毎の持続的接続を含む Sybase 接続の最大数。 ー1 は制限無しを意味します。
- sybase.min_error_severity integer
出力するエラーの重要度の下限。
- sybase.min_message_severity integer
出力するエラーの重要度の下限。
- sybase.compatability_mode boolean
PHP 3.0の古いバージョンとの互換モード。onの場合、結果を 文字列データとして処理する代わりにPHPが自動的にSybaseの型に基づ き結果の型を決めるようにします。この互換モードがサポートされ続け ることはおそらくないため、自分のコードに必要な変更を行い、このオ プションをoffにしてください。
- magic_quotes_sybase boolean
magic_quotes_sybaseがonの場合、 magic_quotes_gpc またはmagic_quotes_runtime が有効の時にシングルクオートはバックスラッシュではなくシングルク オートでエスケープされます。
注意: magic_quotes_sybaseがONの時に、 magic_quotes_gpcの設定を完全に上書きする ことに注意してください。この場合、たとえ magic_quotes_gpcが有効の場合でも ダブルクオートもバックスラッシュもNULもエスケープされません。
表 2. Sybase-CT configuration options
| 名前 | デフォルト | 変更の可否 | 変更履歴 |
|---|---|---|---|
| sybct.allow_persistent | "1" | PHP_INI_SYSTEM | PHP <= 4.0.2 では PHP_INI_ALL、PHP 4.0.2 以降で使用可能です。 |
| sybct.max_persistent | "-1" | PHP_INI_SYSTEM | PHP <= 4.0.2 では PHP_INI_ALL、PHP 4.0.2 以降で使用可能です。 |
| sybct.max_links | "-1" | PHP_INI_SYSTEM | PHP <= 4.0.2 では PHP_INI_ALL、PHP 4.0.2 以降で使用可能です。 |
| sybct.min_server_severity | "10" | PHP_INI_ALL | PHP 4.0.2 以降で使用可能です。 |
| sybct.min_client_severity | "10" | PHP_INI_ALL | PHP 4.0.2 以降で使用可能です。 |
| sybct.hostname | NULL | PHP_INI_ALL | PHP 4.0.2 以降で使用可能です。 |
| sybct.deadlock_retry_count | "0" | PHP_INI_ALL | PHP 4.3.0 以降で使用可能です。 |
以下に設定ディレクティブに関する 簡単な説明を示します。
- sybct.allow_persistent boolean
持続的なSybase-CT接続を使用可能にするかどうか。 デフォルトは、onです。
- sybct.max_persistent integer
プロセス毎の持続的なSybase接続の最大数。-1は制限無しを意味します。
- sybct.max_links integer
プロセス毎の持続的接続を含むSybase-CT接続の最大数。 ー1は制限無しを意味します。
- sybct.min_server_severity integer
sybct.min_server_severity以上の重要度を有するサーバーメッセージ は警告を出力します。この値は、スクリプト内で sybase_min_server_severity()をコールすること により設定することも可能です。デフォルトは10で、 重要度がこの値以上の情報が出力されます。
- sybct.min_client_severity integer
sybct.min_client_severity以上の重要度を有する クライアントライブラリメッセージが警告として出力されます。 この値は、スクリプトで sybase_min_client_severity()をコールすること により設定することも可能です。デフォルトは10で、 出力を結果的に無効にしています。
- sybct.login_timeout integer
接続の試みが失敗した場合に、成功するまで待ち続ける最大の秒数。 接続の試みがタイムアウトした際にもし max_exeution_time をこえていたら、 接続失敗の処理をする前にスクリプトが終了してしまうことに注意しましょう。 デフォルトは 1 分です。
- sybct.timeout integer
select_db やクエリ操作が失敗した場合に、成功するまで待ち続ける秒数。 操作がタイムアウトした際にもし max_exeution_time をこえていたら、 接続失敗の処理をする前にスクリプトが終了してしまうことに注意しましょう。 デフォルトは無制限です。
- sybct.hostname string
sp_whoで表示するための接続を行うホスト名。デフォルトはありません。
- sybct.deadlock_retry_count int
デッドロックが発生した場合に何回目まで再試行するかを設定します。 デフォルトは -1 すなわち "永遠に" です。
PHP_INI_* 定数の詳細および定義については 付録G を参照してください。
定義済み定数
定数は定義されていません。
- 目次
- sybase_affected_rows -- 直近のクエリで変更された行の数を得る
- sybase_close -- Sybase 接続を閉じる
- sybase_connect -- Sybase サーバ接続をオープンする
- sybase_data_seek -- 内部行ポインタを移動する
- sybase_deadlock_retry_count -- デッドロックの再試行回数を設定する
- sybase_fetch_array -- 行を配列として取り込む
- sybase_fetch_assoc -- 結果の行を連想配列として取得する
- sybase_fetch_field -- 結果からフィールド情報を取得する
- sybase_fetch_object -- 行をオブジェクトとして取り込む
- sybase_fetch_row -- 行を配列として取得する
- sybase_field_seek -- フィールドオフセットを設定する
- sybase_free_result -- 結果メモリを開放する
- sybase_get_last_message -- サーバから直近のメッセージを返す
- sybase_min_client_severity -- クライアントの severity の最小値を設定する
- sybase_min_error_severity -- エラーの severity の最小値を設定する
- sybase_min_message_severity -- メッセージの severity の最小値を設定する
- sybase_min_server_severity -- サーバの severity の最小値を設定する
- sybase_num_fields -- 結果におけるフィールドの数を取得する
- sybase_num_rows -- 結果における行の数を取得する
- sybase_pconnect -- Sybase の持続的な接続をオープンする
- sybase_query -- Sybase クエリを送信する
- sybase_result -- 結果データを取得する
- sybase_select_db -- Sybase データベースを選択する
- sybase_set_message_handler -- サーバでメッセージが発生した際にコールされるハンドラを指定する
- sybase_unbuffered_query -- Sybase クエリを送信し、ブロックしない
PHP and Sybase 15
# cat /opt/sybase/SYBASE.sh >> /etc/profile
# exit
Make new logon
# vi /var/build/php-5.2.3/ext/sybase_ct/php_sybase_ct.h
change this line ...
#define CTLIB_VERSION CS_VERSION_100
...to...
#define CTLIB_VERSION CS_VERSION_150
# ln -sd /opt/sybase /home/sybase
# cp /opt/sybase/OCS-15_0/lib/libsybcomn.a /opt/sybase/OCS-15_0/lib/libcomn.a
# cp /opt/sybase/OCS-15_0/lib/libsybcs.a /opt/sybase/OCS-15_0/lib/libs.a
# cp /opt/sybase/OCS-15_0/lib/libsybct.a /opt/sybase/OCS-15_0/lib/libct.a
# cp /opt/sybase/OCS-15_0/lib/libsybintl.a /opt/sybase/OCS-15_0/lib/libintl.a
The new file /etc/ld.so.conf.d/sybase it must have the line
/opt/sybase/OCS-15_0/lib
# ldconfig
BUILD PHP
# ./configure --with-apxs2=/usr/sbin/apxs --with-config-file-path=/etc/ --with-sybase-ct=/opt/sybase/OCS-15_0
# make
# make install
# cp php.ini-dist /etc/php.ini
Change display_erros=On to display_erros=Off
Edit Apache's httpd.conf file to associate .php files with a MIME type:
#
# PHP script support
#
AddType application/x-httpd-php .php
I've finally got PHP 5.0.5 running under Apache2 on Solaris 8 ... connecting to Sybase ASE servers 12.0 and 12.5 using CT-LIB 12.5.
The following was my build procedure -
Build Apache:
./configure \
--prefix=/usr/local/apache2 \
--enable-so
make
make install
Edit httpd.conf, adjusting directives to suit the local environment.
Following advice given above, update the Sybase version string in the PHP sybase_ct module header file:
vi /var/build/php-5.0.5/ext/sybase_ct/php_sybase_ct.h
change this line ...
#define CTLIB_VERSION CS_VERSION_100
...to...
#define CTLIB_VERSION CS_VERSION_125
Build PHP:
SYBASE=/..../..../sybase12_5 <<-- path to your Sybase distribution root
SYBASE_OCS=OCS-12_5
LD_LIBRARY_PATH=$SYBASE/$SYBASE_OCS/lib
export SYBASE SYBASE_OCS PATH LD_LIBRARY_PATH
./configure \
--prefix=/usr/local/php \
--with-sybase-ct=$SYBASE/$SYBASE_OCS \
--enable-static=sybase-ct \
--with-apxs2=/usr/local/apache2/bin/apxs \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm
make
make test
NOTE: 'make test' will almost certainly fail all of the Sybase functionality, unless you update the test include file to use valid connectivity details for your local server:
vi /var/build/php-5.0.5/ext/sybase_ct/tests/test.inc
// Change if needed
define('HOST', '****');
define('USER', '****');
define('PASSWORD', '****');
make install
Edit Apache's httpd.conf file to associate .php files with a MIME type:
#
# PHP script support
#
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Edit the apachectl script, inserting the following variable declarations after environment variables are imported:
SYBASE=/..../..../sybase12_5
SYBASE_OCS=OCS-12_5
LD_LIBRARY_PATH=$SYBASE/$SYBASE_OCS/lib:$LD_LIBRARY_PATH
export SYBASE SYBASE_OCS LD_LIBRARY_PATH
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:
dataservername_ds
<tab> master tcp ether <hostname> <port>
<tab> query tcp ether <hostname> <port>
(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:
ldd /usr/local/apache2/modules/libphp5.so
libtcl.so => /.../sybase12_5/OCS-12_5/lib/libtcl.so
libintl.so.1 => /.../sybase12_5/OCS-12_5/lib/libintl.so.1
libcomn.so => /.../sybase12_5/OCS-12_5/lib/libcomn.so
libct.so => /.../sybase12_5/OCS-12_5/lib/libct.so
libcs.so => /.../sybase12_5/OCS-12_5/lib/libcs.so
...
<snip other libraries>
...
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 just want to report that, like explained in bug #27562, selective stored procedures (like sp_helpdb) don't return a resultset with freeTDS >= 0.62. (using php <= 4.3.9)
If you have installed such releases of freeTDS, downgrade to 0.61.x.
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).
For Sybase/iAnywhere SQL Anywhere (a.k.a Adaptive Server Anywhere, a.k.a. ASA), you likely should try the SQLAnywhere PHP module [which now ships with ASA as of 9.0.2]:
http://www.ianywhere.com/developer/code_samples/sqlany_php_module.html
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)
Hope this helps,
greg.fenton
This is way to compile Sybase ASE 12.5 with PHP5.0.0 and Apache 2 on Linux:
- install apache
- install ase1252_de_linux.tgz to /opt/sybase-12.5
- shell:# ln -s /opt/sybase-12.5 /opt/sybase
- edit phpsrc/configure and remove all '-linsck'
- edit phpsrc/ext/sybase-ct/php_sybase_ct.h and change CTLIB_VERSION CS_VERSION_100 to 125
- shell:# export SYBASE=/opt/sybase
- phpsrc/configure --with-sybase-ct=/opt/sybase/OCS-12_5
- phpsrc/make and make install
- edit apache2/conf/httpd.conf and add AddType... .php
- create /opt/sybase/interfaces file
SERVERNAME
[tab!]master tcp ether ipAddress port
[tab!]query tcp ether ipAddress port
- apache2/bin/apachectl start
I hope, that I save your time.
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.
I solved my connection problems by setting ENV variables directly in PHP.
putenv ("SYBASE=/opt/sybase");
putenv ("SYBPLATFORM=linux");
putenv ("LD_LIBRARY_PATH=/opt/sybase/lib");
putenv ("LC_ALL=default");
putenv ("PATH=\"/opt/sybase/bin:$PATH\"");
putenv ("DSQUERY=SYBASE");
--
Martin Sarajervi
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 [...])
--
Diego Dal Cero.
A note for all who may be struggling... Microsoft did away with the ct-lib support in SQL Server 2000.
I played with it and found a couple of articles related to it on google. A workaround/different method would be preferrable. Anybody?
Compiling PHP with Sybase ASE 12.5 on Linux.
Assuming that you have installed the Sybase ASE 12.5 client in linux, and you have the SYBASE env variable set, you can compile PHP >= 4.0.6 with Sybase ASE 12.5.
Just use:
--with-sybase-ct=$SYBASE/OCS
instead of
--with-sybase-ct=$SYBASE
Freetds 5.2 bugs!!
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"
Feel free to contact us at
aikok@netfront.net
or
elee@kinwai.net
German Chu & Eagle Lee
For those, who might want to use SyBase client not only under Linux, you may try to use open-source FreeTDS library - http://www.freetds.org
Also there's how-to for FreeTDS and PHP:
http://www.freetds.org/userguide/php.html
If you have a Linux machine with Sybase ASE 11.9.2, Php 4.0.6, Apache and Sybase-ct library, don't upgrade to Sybase ASE 12.5 yet, or Apache will stop working.
Since 12.5 is newer than 4.0.6, I guess this will be fixed soon.
If you use IIS and sybase-ct library, be sure to use PHP 4.0.6 or higher, since older version caused crashes.
maybe it can help.
my database is ASE
this is my script....
<?
$cnn = sybase_connect("db_server","sa","password");
$result = sybase_query("Select itemno,stockno from your_db..your_table");
$i = 0;
while ($r = sybase_fetch_array($result)) {
$i++;
$itemno = $r["itemno"];
$stockno = $r["stockno"];
echo "$i $stockno $itemno <br>";
}
?>
note that I did not use the
sybase_select_db("db") function because ASE had a default database.
thx...
It's important to note that sybase_ct connect or pconnect were causing GPF.
If you experienced this problem, just update PHP to 4.0.6.
A bit more about blobs:
If you want to retrieve blobs without them getting truncated, do a 'set textsize value' query first.
about sybase-ct library
You can download the file from php.net but the samples in the tar (and php) maybe not compile I have this problem in some systems (but not in others with old librarys and old gcc).
Try freetds from www.freetds.org that is ok!
System wthout trouble
Debian 2.1 gcc (2.7.2.3) libc-2.0.7.so
System With trouble
Debian 2.2 gcc (2.95.2) libc-2.1.3.so
RedHat 6.2 gcc [egcs] (2.91.66) libc-2.1.3.so
Please refer to mssql if you try to connect to MS SQL Server!!!
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.
If you get a segfault with sybase-ct, add a en_US entry to your $SYBASE/locales/locales.dat file:
[linux]
locale = en_US, us_english, iso_1
...
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...
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:
SERVERNAME
query tcp ether 172.16.1.4 4100
master tcp ether 172.16.1.4 4100
(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!
To store an image file into Sybase try this :
$data = bin2hex(fread(fopen($image,"r"), filesize($image)));
//don't forget the 0x before the hex data.
if(! sybase_query("INSERT INTO test_image (image) VALUES (0x".$data.")")) die ("Unable to store the image.");
To retrieve it just do a select and use a hex2bin function (this one has been submitted by carl@five-ten-sg.com and is the fastest) :
function hex2bin($data) {
$len = strlen($data);
return pack("H" . $len, $data);
}
PS : use CT-lib rather than DB-lib (Sybase doesn't work on it anymore!)
