php 与 sybase 数据库的联接

来源:互联网 发布:广东电信网络测速 编辑:程序博客网 时间:2024/05/22 04:47

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 数据库函数库

sybase_connect

连上数据库。

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

返回值: 整数

函数种类: 数据库功能

 

  内容说明

本函数用来打开与 Sybase 数据库的连接。参数 servername 为欲连上的数据库服务器名称。参数 username 及 password 可省略,分别为连接使用的帐号及密码。使用本函数需注意早点关闭数据库,以减少系统的负担。连接成功则返回数据库的连接代号,失败返回 false 值。


函数:sybase_select_db()

 

Sybase 数据库函数库

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 数据库函数库

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 数据库函数库

sybase_affected_rows

取得最后 query 影响的列数。

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

返回值: 整数

函数种类: 数据库功能

 

  内容说明

本函数用来取得最后一次对数据库下 query 指令所影响的列数,会影响的为 INSERT、UPDATE 或 DELETE 等指令,而 SELECT 不会影响。参数 link_identifier 可省略,为打开数据库的连接代号。返回值即为列数。

函数:sybase_data_seek()


 

Sybase 数据库函数库

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 数据库函数库

sybase_fetch_array

返回数组资料。

语法: array sybase_fetch_array(int result);

返回值: 数组

函数种类: 数据库功能

 

  内容说明

本函数用来将查询结果 result 拆到数组变量中。若 result 没有资料,则返回 false 值。而本函数可以说是 sybase_fetch_row() 的加强函数,除可以将返回列及数字索引放入数组之外,还可以将文字索引放入数组中。

 

  使用范例

这是 joey@samaritan.com (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 数据库函数库

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 数据库函数库

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 数据库函数库

sybase_fetch_row

返回单列的各字段。

语法: array sybase_fetch_row(int result);

返回值: 数组

函数种类: 数据库功能

 

  内容说明

本函数用来将查询结果 result 之单列拆到数组变量中。数组的索引是数字索引,第一个的索引值是 0。若 result 没有资料,则返回 false 值。

函数:sybase_field_seek()


 

Sybase 数据库函数库

sybase_field_seek

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

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

返回值: 整数

函数种类: 数据库功能

 

  内容说明

本函数配置目前的指针到返回值的特定字段中。参数 result 为返回值代码。参数 field_offset 则为指定的字段序数。

 

  函数:sybase_free_result()


 

Sybase 数据库函数库

sybase_free_result

释放返回占用内存。

语法: int sybase_free_result(int result);

返回值: 整数

函数种类: 数据库功能

 

  内容说明

本函数可以释放目前 Sybase 数据库 query 返回所占用的内存。一般只有在非常担心在内存的使用上可能会不足的情形下才会用本函数。PHP 程序会在结束时自动释放。

函数:sybase_num_fields()


 

Sybase 数据库函数库

sybase_num_fields

取得返回字段的数目。

语法: int sybase_num_fields(int result);

返回值: 整数

函数种类: 数据库功能

 

  内容说明

本函数可以得到返回字段的数目。参数 result 为返回值代码。

函数:sybase_num_rows()


 

Sybase 数据库函数库

sybase_num_rows

取得返回列的数目。

语法: int sybase_num_rows(int result);

返回值: 整数

函数种类: 数据库功能

 

  内容说明

本函数可以得到返回列的数目。参数 result 为返回值代码。

函数:sybase_pconnect()


 

Sybase 数据库函数库

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: 选择一个数据库。

 



 

原创粉丝点击