php 與 sybase 數據庫的聯接

php 與 sybase 數據庫的聯接

1、安裝SYBASE客戶端,確定sybase central連結成功;

2、修改%windows%目錄下的php.ini:

;extensions=php_sybase_ct.dll       ----》 去掉前面分號
同時,當應用上面的動態連接庫時,則連MS SQL的動態連接庫必須關閉,否則會造成衝突!即:
extension=php_mssql.dll這個要註釋掉!
         確定php的extensions目錄裏有php_sybase_ct.dll 文件,如果是win2000,還要將php/extensions中的php_sybase_ct.dll文件copy到system32下。

3、用PHPINFO()確認配無錯

我要將extensions 裡面的幾個功例如 pdf 和 Sybase_ct
所以將 php.ini 裡面 ;extensions=php_pdf. dll 和 ;extensions=php_sybase_ct.dll 前面的分號拿掉 儲存之後重新啟動apache伺服器卻出現下列訊息
unknown():unable to load dynamic library 'c:/PHP/extensions/php_sybase_ct.dll' -找不到指定的模組 所以無法開啟 但是我檢查過 該檔案有在上述目錄下 也有將該檔案複製到 /winnt/system32/ 下面
想請教要如何解決此一問題呢 謝謝
使用的作業系統為 windows xp ,Apache 2.0.49, PHP 4.3.6

後來上 www.php.net 找了相關的問題 此問題已經解決了
主要的問題在於和 sybase 相關的 clinet library 沒有安裝
先去 http://www.dependencywalker.com 下載depends21_x86
軟體 該軟體可以幫你尋找 某執行檔或是 .dll 需要的相關 檔案
我開啟 php_sybase_ct.dll 之後 軟體就告訴我缺了 libct.dll
libcs.dll 等等 檔案 於是就去 sybase網站下載相關檔案
放入 /Winnt/system32/ 之後 重新啟動Apache伺服器就沒有
上述的問題了 給各位做個參考

例子 1. sybase_connect() example

<?php
    $link
= sybase_connect('SYBASE', '', '')
            or die(
"Could not connect !");
    echo
"Connected successfully";
    
sybase_close($link);
?>

See also sybase_pconnect() and sybase_close().

sybase_connect

(PHP 3, PHP 4 , PHP 5)

sybase_connect -- Opens a Sybase server connection

Description

resource sybase_connect ( [string servername [, string username [, string password [, string charset [, string appname]]]]])

Returns a positive Sybase link identifier on success, or FALSE on failure.

sybase_connect() establishes a connection to a Sybase server. The servername argument has to be a valid servername that is defined in the 'interfaces' file.

In case a second call is made to sybase_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.

The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling sybase_close().

 

 

Sybase 數據庫函數庫

 

函數:sybase_connect()

 


sybase_connect

連上數據庫。

語法: int sybase_connect(string [servername], string [username], string [password]);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數用來打開與 Sybase 數據庫的連接。參數 servername 爲欲連上的數據庫服務器名稱。參數 username 及 password 可省略,分別爲連接使用的帳號及密碼。使用本函數需注意早點關閉數據庫,以減少系統的負擔。連接成功則返回數據庫的連接代號,失敗返回 false 值。


函數:sybase_select_db()

 


sybase_select_db

選擇一個數據庫。

語法: boolean sybase_select_db(string database_name, int [link_identifier]);

返回值: 布爾值

函數種類: 數據庫功能

 

 
內容說明

本函數選擇 Sybase 中的數據庫以供之後的資料查詢作業 (query) 處理。成功返回 true,失敗則返回 false。

sybase_query

送出一個 query 字符串。

語法: boolean sybase_query(string query, int plink_identifier]);

返回值: 布爾值

函數種類: 數據庫功能

 

 
內容說明

本函數送出 query 字符串供 Sybase 做相關的處理或者執行。若沒有指定 link_identifier 參數,則程序會自動尋找最近打開的 ID。成功則返回 true 值。

函數:sybase_result()

 


sybase_result

取得查詢 (query) 的結果。

語法: int sybase_result(int result, int row, mixed field);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數取得一格 query 的結果。參數 field 可以是字段名稱、順序或者是 fieldname.tablename 的格式。在返回資料量少時,可以使用本函數來處理。當數據庫大時,本函數的效率就有待考量了,這時可以使用較有效率的 sybase_fetch_row()sybase_fetch_array()sybase_fetch_object() 等函數。

函數:sybase_affected_rows()

 


sybase_affected_rows

取得最後 query 影響的列數。

語法: int sybase_affected_rows(int [link_identifier]);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數用來取得最後一次對數據庫下 query 指令所影響的列數,會影響的爲 INSERT、UPDATE 或 DELETE 等指令,而 SELECT 不會影響。參數 link_identifier 可省略,爲打開數據庫的連接代號。返回值即爲列數。

函數:sybase_data_seek()

 


sybase_data_seek

移動列指針。

語法: boolean sybase_data_seek(int result_identifier, int row_number);

返回值: 布爾值

函數種類: 數據庫功能

 

 
內容說明

本函數用來移動 Sybase 資料表中的列指針到指定的列上,可供 sybase_fetch_row() 等函數使用。參數 result_identifier 爲查詢的代號值。參數 row_number 則爲欲移往的列數。若失敗則返回 false 值。

函數:sybase_fetch_array()

 


sybase_fetch_array

返回數組資料。

語法: array sybase_fetch_array(int result);

返回值: 數組

函數種類: 數據庫功能

 

 
內容說明

本函數用來將查詢結果 result 拆到數組變量中。若 result 沒有資料,則返回 false 值。而本函數可以說是 sybase_fetch_row() 的加強函數,除可以將返回列及數字索引放入數組之外,還可以將文字索引放入數組中。

 

 
使用範例

這是 [email protected] (22-Feb-1999) 所提出的例子

<?php
$q 
sybase_query("SELECT COUNT(DISTINCT OPPORTUNITY_ID) FROM M_OPP_INTERESTS WHERE INTEREST_ID = $i_id"$db);
while (
$op_by_int sybase_fetch_array($q)) {
while (list(
$k$v) = each($op_by_int)) {
echo 
"/$op[$k] => $v/n";
}
?>

返回資料如下
$op[0] => 2164
$op[computed] => 2164

函數:sybase_fetch_field()

 


sybase_fetch_field

取得字段信息。

語法: object sybase_fetch_field(int result, int field_offset);

返回值:

函數種類: 數學運算

 

 
內容說明

本函數返回的類資料爲 result 的字段 (Column) 信息。返回類的屬性如下:

  • name - 字段名稱
  • column_source -字段所在表格的資料表名稱
  • max_length - 字段的最大長度
  • numeric - 若爲 1 表示本字段爲數字類型 (numeric)
  函數:sybase_fetch_object()

 


sybase_fetch_object

返回類資料。

語法: object sybase_fetch_object(int result);

返回值:

函數種類: 數據庫功能

 

 
內容說明

本函數用來將查詢結果 result 拆到類變量中。使用方法和 sybase_fetch_array() 幾乎相同,不同的地方在於本函數返回資料是類而不是數組。若 result 沒有資料,則返回 false 值。另外值得注意的地方是,取回的類資料的索引只能是文字而不能用數字,這是因爲類的特性。類資料的特性中所有的屬性 (property) 名稱都不能是數字,因此只好乖乖使用文字字符串當索引了。關於速度方面,本函數的處理速度幾乎和 sybase_fetch_array()sybase_fetch_row() 二函數差不多,要用哪個函數還是看使用的需求決定。

函數:sybase_fetch_row()

 


sybase_fetch_row

返回單列的各字段。

語法: array sybase_fetch_row(int result);

返回值: 數組

函數種類: 數據庫功能

 

 
內容說明

本函數用來將查詢結果 result 之單列拆到數組變量中。數組的索引是數字索引,第一個的索引值是 0。若 result 沒有資料,則返回 false 值。

函數:sybase_field_seek()

 


sybase_field_seek

配置指針到返回值的某字段。

語法: int sybase_field_seek(int result, int field_offset);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數配置目前的指針到返回值的特定字段中。參數 result 爲返回值代碼。參數 field_offset 則爲指定的字段序數。

 

  函數:sybase_free_result()

 


sybase_free_result

釋放返回佔用內存。

語法: int sybase_free_result(int result);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數可以釋放目前 Sybase 數據庫 query 返回所佔用的內存。一般只有在非常擔心在內存的使用上可能會不足的情形下才會用本函數。PHP 程序會在結束時自動釋放。

函數:sybase_num_fields()

 


sybase_num_fields

取得返回字段的數目。

語法: int sybase_num_fields(int result);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數可以得到返回字段的數目。參數 result 爲返回值代碼。

函數:sybase_num_rows()

 


sybase_num_rows

取得返回列的數目。

語法: int sybase_num_rows(int result);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數可以得到返回列的數目。參數 result 爲返回值代碼。

函數:sybase_pconnect()

 


sybase_pconnect

打開服務器持續連接。

語法: int sybase_pconnect(string [servername], string [username], string [password]);

返回值: 整數

函數種類: 數據庫功能

 

 
內容說明

本函數和 sybase_connect() 雷同。不同的地方在於使用本函數打開數據庫時,程序會先尋找是否曾經執行過本函數,若執行過則返回先前執行的 ID。另一個不同的地方是本函數無法使用 sybase_close() 關閉數據庫。參數 servername 爲欲連上的數據庫服務器名稱。參數 username 及 password 可省略,分別爲連接使用的帳號及密碼。

 

 

Sybase Functions

簡介

 

需求

 

安裝

To enable Sybase-DB support configure PHP --with-sybase[=DIR]. DIR is the Sybase home directory, defaults to /home/sybase. To enable Sybase-CT support configure PHP --with-sybase-ct[=DIR]. DIR is the Sybase home directory, defaults to /home/sybase.

運行時配置

這些函數的行爲受到全局配置文件 php.ini 的影響。

 

表格 1. Sybase configuration options

Name Default Changeable
sybase.allow_persistent "On" PHP_INI_SYSTEM
sybase.max_persistent "-1" PHP_INI_SYSTEM
sybase.max_links "-1" 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 "Off" PHP_INI_SYSTEM
magic_quotes_sybase "Off" PHP_INI_ALL

 

以下是該配置選項的簡要解釋。

 

 

sybase.allow_persistent boolean

Whether to allow persistent Sybase connections.

sybase.max_persistent integer

The maximum number of persistent Sybase connections per process. -1 means no limit.

sybase.max_links integer

The maximum number of Sybase connections per process, including persistent connections. -1 means no limit.

sybase.min_error_severity integer

Minimum error severity to display.

sybase.min_message_severity integer

Minimum message severity to display.

sybase.compatability_mode boolean

Compatability mode with old versions of PHP 3.0. If on, this will cause PHP to automatically assign types to results according to their Sybase type, instead of treating them all as strings. This compatability mode will probably not stay around forever, so try applying whatever necessary changes to your code, and turn it off.

magic_quotes_sybase boolean

If magic_quotes_sybase is on, a single-quote is escaped with a single-quote instead of a backslash if magic_quotes_gpc or magic_quotes_runtime are enabled.

注: Note that when magic_quotes_sybase is ON it completely overrides magic_quotes_gpc . In this case even when magic_quotes_gpc is enabled neither double quotes, backslashes or NUL's will be escaped.

 

 

表格 2. Sybase-CT configuration options

Name Default Changeable
sybct.allow_persistent "On" PHP_INI_SYSTEM
sybct.max_persistent "-1" PHP_INI_SYSTEM
sybct.max_links "-1" PHP_INI_SYSTEM
sybct.min_server_severity "10" PHP_INI_ALL
sybct.min_client_severity "10" PHP_INI_ALL
sybct.hostname NULL PHP_INI_ALL
sybct.deadlock_retry_count "-1" PHP_INI_ALL

 

以下是該配置選項的簡要解釋。

 

 

sybct.allow_persistent boolean

Whether to allow persistent Sybase-CT connections. The default is on.

sybct.max_persistent integer

The maximum number of persistent Sybase-CT connections per process. The default is -1 meaning unlimited.

sybct.max_links integer

The maximum number of Sybase-CT connections per process, including persistent connections. The default is -1 meaning unlimited.

sybct.min_server_severity integer

Server messages with severity greater than or equal to sybct.min_server_severity will be reported as warnings. This value can also be set from a script by calling sybase_min_server_severity(). The default is 10 which reports errors of information severity or greater.

sybct.min_client_severity integer

Client library messages with severity greater than or equal to sybct.min_client_severity will be reported as warnings. This value can also be set from a script by calling sybase_min_client_severity(). The default is 10 which effectively disables reporting.

sybct.login_timeout integer

The maximum time in seconds to wait for a connection attempt to succeed before returning failure. Note that if max_execution_time has been exceeded when a connection attempt times out, your script will be terminated before it can take action on failure. The default is one minute.

sybct.timeout integer

The maximum time in seconds to wait for a select_db or query operation to succeed before returning failure. Note that if max_execution_time has been exceeded when an operation times out, your script will be terminated before it can take action on failure. The default is no limit.

sybct.hostname string

The name of the host you claim to be connecting from, for display by sp_who. The default is none.

sybct.deadlock_retry_count int

Allows you to to define how often deadlocks are to be retried. The default is -1, or "forever".

 

For further details and definition of the PHP_INI_* constants see ini_set().

預定義常量

該擴展模塊未定義任何常量。

目錄
sybase_affected_rows -- Gets number of affected rows in last query
sybase_close -- Closes a Sybase connection
sybase_connect -- Opens a Sybase server connection
sybase_data_seek -- Moves internal row pointer
sybase_deadlock_retry_count -- Sets the deadlock retry count
sybase_fetch_array -- Fetch row as array
sybase_fetch_assoc -- Fetch a result row as an associative array
sybase_fetch_field -- Get field information from a result
sybase_fetch_object -- Fetch a row as an object
sybase_fetch_row -- Get a result row as an enumerated array
sybase_field_seek -- Sets field offset
sybase_free_result -- Frees result memory
sybase_get_last_message -- Returns the last message from the server
sybase_min_client_severity -- Sets minimum client severity
sybase_min_error_severity -- Sets minimum error severity
sybase_min_message_severity -- Sets minimum message severity
sybase_min_server_severity -- Sets minimum server severity
sybase_num_fields -- Gets the number of fields in a result set
sybase_num_rows -- Get number of rows in a result set
sybase_pconnect -- Open persistent Sybase connection
sybase_query -- Sends a Sybase query
sybase_result -- Get result data
sybase_select_db -- Selects a Sybase database
sybase_set_message_handler -- Sets the handler called when a server message is raised
sybase_unbuffered_query -- Send a Sybase query and do not block

 

本函數庫共有 16 個函數

這個函數庫和 SQL Server 數據庫函數庫幾乎完全相同,實際上是本函數先出現,之後纔出現 SQL Server 數據庫函數庫。而就用戶觀點 Sybase 和 MS SQL Server 6.x 也是幾乎相同的。當然 MS SQL Server 7.0 之後的差異就比較大了。

sybase_affected_rows: 取得最後 query 影響的列數。
sybase_close: 關閉與數據庫的連接。
sybase_connect: 連上數據庫。
sybase_data_seek: 移動列指針。
sybase_fetch_array: 返回數組資料。
sybase_fetch_field: 取得字段信息。
sybase_fetch_object: 返回類資料。
sybase_fetch_row: 返回單列的各字段。
sybase_field_seek: 配置指針到返回值的某字段。
sybase_free_result: 釋放返回佔用內存。
sybase_num_fields: 取得返回字段的數目。
sybase_num_rows: 取得返回列的數目。
sybase_pconnect: 打開服務器持續連接。
sybase_query: 送出一個 query 字符串。
sybase_result: 取得查詢 (query) 的結果。
sybase_select_db: 選擇一個數據庫。

 



 

發佈了9 篇原創文章 · 獲贊 1 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章