Sybase

目录

Warning

As of PHP 7.0.0, the sybase_ct extension has been removed.

安装/配置

目录

需求

构建此扩展不需要其他扩展。

安装

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.

Note:

As of PHP 5.3.0, the Sybase extension has been superseded by the sybase_ct extension and is no longer maintained. To continue using sybase you must use the sybase_ct extension.

As of PHP 7.0.0, the sybase_ct extension has been removed.

运行时配置

这些函数的行为受 php.ini 中的设置影响。

名字默认可修改范围更新日志
sybase.allow_persistent"1"PHP_INI_ALLPHP_INI_ALL in PHP <= 4.0.2. PHP_INI_SYSTEM in PHP <= 4.0.3.
sybase.max_persistent"-1"PHP_INI_ALLPHP_INI_ALL in PHP <= 4.0.2. PHP_INI_SYSTEM in PHP <= 4.0.3.
sybase.max_links"-1"PHP_INI_ALLPHP_INI_ALL in PHP <= 4.0.2. PHP_INI_SYSTEM in PHP <= 4.0.3.
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_ALLDeprecated in PHP 5.3.0. Removed in PHP 5.4.0.

这是配置指令的简短说明。

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.

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. This setting is also respected by addslashes and stripslashes.

Note:

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.

Warning 本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除

名字默认可修改范围更新日志
sybct.deadlock_retry_count"0"PHP_INI_ALLAvailable since PHP 4.3.0.

这是配置指令的简短说明。

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.deadlock_retry_count int
Allows you to define how often deadlocks are to be retried. The default is 0, value -1 means "forever".

有关 PHP_INI_* 样式的更多详情与定义,见 配置可被设定范围

资源类型

此扩展没有定义资源类型。

预定义常量

此扩展没有定义常量。

sybase_affected_rows

Gets number of affected rows in last query

Warning

This function was REMOVED in PHP 7.0.0.

说明

int sybase_affected_rows ([ resource $link_identifier ] )

sybase_affected_rows returns the number of rows affected by the last INSERT, UPDATE or DELETE query on the server associated with the specified link identifier.

This command is not effective for SELECT statements, only on statements which modify records. To retrieve the number of rows returned from a SELECT, use sybase_num_rows.

参数

link_identifier
If the link identifier isn't specified, the last opened link is assumed.

返回值

Returns the number of affected rows, as an integer.

范例

示例 #1 Delete-Query

<?php
/* connect to database */
sybase_connect('SYBASE', '', '') or
die("Could not connect");
sybase_select_db("db");

sybase_query("DELETE FROM sometable WHERE id < 10");
printf("Records deleted: %d\n", sybase_affected_rows());
?>

以上例程会输出:

Records deleted: 10

参见

  • sybase_num_rows

sybase_close

Closes a Sybase connection

Warning

This function was REMOVED in PHP 7.0.0.

说明

bool sybase_close ([ resource $link_identifier ] )

sybase_close closes the link to a Sybase database that's associated with the specified link link_identifier.

Note that this isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.

sybase_close will not close persistent links generated by sybase_pconnect.

参数

link_identifier
If the link identifier isn't specified, the last opened link is assumed.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • sybase_connect
  • sybase_pconnect

sybase_connect

Opens a Sybase server connection

Warning

This function was REMOVED in PHP 7.0.0.

说明

resource sybase_connect ([ string $servername [, string $username [, string $password [, string $charset [, string $appname [, bool $new = FALSE ]]]]]] )

sybase_connect establishes a connection to a Sybase server.

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.

参数

servername
The servername argument has to be a valid servername that is defined in the 'interfaces' file.

username
Sybase user name

password
Password associated with username.

charset
Specifies the charset for the connection

appname
Specifies an appname for the Sybase connection. This allow you to make separate connections in the same script to the same database. This may come handy when you have started a transaction in your current connection, and you need to be able to do a separate query which cannot be performed inside this transaction.

new
Whether to open a new connection or use the existing one.

返回值

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

更新日志

版本说明
5.3.0The new parameter was added.

范例

示例 #1 sybase_connect example

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

参见

  • sybase_pconnect
  • sybase_close

sybase_data_seek

Moves internal row pointer

Warning

This function was REMOVED in PHP 7.0.0.

说明

bool sybase_data_seek ( resource $result_identifier , int $row_number )

sybase_data_seek moves the internal row pointer of the Sybase result associated with the specified result identifier to pointer to the specified row number. The next call to sybase_fetch_row would return that row.

参数

result_identifier

row_number

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • sybase_fetch_row

sybase_deadlock_retry_count

Sets the deadlock retry count

Warning

This function was REMOVED in PHP 7.0.0.

说明

void sybase_deadlock_retry_count ( int $retry_count )

Using sybase_deadlock_retry_count, the number of retries can be defined in cases of deadlocks. By default, every deadlock is retried an infinite number of times or until the process is killed by Sybase, the executing script is killed (for instance, by set_time_limit) or the query succeeds.

参数

retry_count
| | | |-----|-------------------------| | -1 | Retry forever (default) | | 0 | Do not retry | | n | Retry n times |

返回值

没有返回值。

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

sybase_fetch_array

Fetch row as array

Warning

This function was REMOVED in PHP 7.0.0.

说明

array sybase_fetch_array ( resource $result )

sybase_fetch_array is an extended version of sybase_fetch_row. In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.

An important thing to note is that using sybase_fetch_array is NOT significantly slower than using sybase_fetch_row, while it provides a significant added value.

参数

result

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.

Note:

When selecting fields with identical names (for instance, in a join), the associative indices will have a sequential number prepended. See the example for details.

范例

示例 #1 Identical fieldnames

<?php

$dbh = sybase_connect('SYBASE', '', '');
$q = sybase_query('SELECT * FROM p, a WHERE p.person_id= a.person_id');
var_dump(sybase_fetch_array($q));
sybase_close($dbh);
?>

The above example would produce the following output (assuming the two tables only have each one column called "person_id"):

array(4) {
  [0]=>
  int(1)
  ["person_id"]=>
  int(1)
  [1]=>
  int(1)
  ["person_id1"]=>
  int(1)
}

参见

  • sybase_fetch_row
  • sybase_fetch_assoc
  • sybase_fetch_object

sybase_fetch_assoc

Fetch a result row as an associative array

Warning

This function was REMOVED in PHP 7.0.0.

说明

array sybase_fetch_assoc ( resource $result )

sybase_fetch_assoc is a version of sybase_fetch_row that uses column names instead of integers for indices in the result array. Columns from different tables with the same names are returned as name, name1, name2, ..., nameN.

An important thing to note is that using sybase_fetch_assoc is NOT significantly slower than using sybase_fetch_row, while it provides a significant added value.

参数

result

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

参见

  • sybase_fetch_row
  • sybase_fetch_array
  • sybase_fetch_object

sybase_fetch_field

Get field information from a result

Warning

This function was REMOVED in PHP 7.0.0.

说明

object sybase_fetch_field ( resource $result [, int $field_offset = -1 ] )

sybase_fetch_field can be used in order to obtain information about fields in a certain query result.

参数

result

field_offset
If the field offset isn't specified, the next field that wasn't yet retrieved by sybase_fetch_field is retrieved.

返回值

Returns an object containing field information.

The properties of the object are:

  • name - column name. if the column is a result of a function, this property is set to computed#N, where #N is a serial number.
  • column_source - the table from which the column was taken
  • max_length - maximum length of the column
  • numeric - 1 if the column is numeric
  • type - datatype of the column

参见

  • sybase_field_seek

sybase_fetch_object

Fetch a row as an object

Warning

This function was REMOVED in PHP 7.0.0.

说明

object sybase_fetch_object ( resource $result [, mixed $object ] )

sybase_fetch_object is similar to sybase_fetch_assoc, with one difference - an object is returned, instead of an array.

Speed-wise, the function is identical to sybase_fetch_array, and almost as quick as sybase_fetch_row (the difference is insignificant).

参数

result

object
Use the second object to specify the type of object you want to return. If this parameter is omitted, the object will be of type stdClass.

返回值

Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.

范例

示例 #1 sybase_fetch_object return as Foo

<?php
    class Foo {
        var $foo, $bar, $baz;
    }

    // {...]
    $qrh= sybase_query('SELECT foo, bar, baz FROM example');
    $foo= sybase_fetch_object($qrh, 'Foo');
    $bar= sybase_fetch_object($qrh, new Foo());
    // {...]
?>

参见

  • sybase_fetch_array
  • sybase_fetch_row

sybase_fetch_row

Get a result row as an enumerated array

Warning

This function was REMOVED in PHP 7.0.0.

说明

array sybase_fetch_row ( resource $result )

sybase_fetch_row fetches one row of data from the result associated with the specified result identifier.

Subsequent call to sybase_fetch_row would return the next row in the result set, or FALSE if there are no more rows.

参数

result

返回值

Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. Each result column is stored in an array offset, starting at offset 0.

PHPSybase
stringVARCHAR, TEXT, CHAR, IMAGE, BINARY, VARBINARY, DATETIME
intNUMERIC (w/o precision), DECIMAL (w/o precision), INT, BIT, TINYINT, SMALLINT
floatNUMERIC (w/ precision), DECIMAL (w/ precision), REAL, FLOAT, MONEY
NULLNULL

参见

  • sybase_fetch_array
  • sybase_fetch_assoc
  • sybase_fetch_object
  • sybase_data_seek
  • sybase_result

sybase_field_seek

Sets field offset

Warning

This function was REMOVED in PHP 7.0.0.

说明

bool sybase_field_seek ( resource $result , int $field_offset )

Seeks to the specified field offset. If the next call to sybase_fetch_field won't include a field offset, this field would be returned.

参数

result

field_offset

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • sybase_fetch_field

sybase_free_result

Frees result memory

Warning

This function was REMOVED in PHP 7.0.0.

说明

bool sybase_free_result ( resource $result )

sybase_free_result only needs to be called if you are worried about using too much memory while your script is running. All result memory will automatically be freed when the script ends. You may call sybase_free_result with the result identifier as an argument and the associated result memory will be freed.

参数

result

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

sybase_get_last_message

Returns the last message from the server

Warning

This function was REMOVED in PHP 7.0.0.

说明

string sybase_get_last_message ( void )

sybase_get_last_message returns the last message reported by the server.

返回值

Returns the message as a string.

参见

  • sybase_min_message_severity

sybase_min_client_severity

Sets minimum client severity

Warning

This function was REMOVED in PHP 7.0.0.

说明

void sybase_min_client_severity ( int $severity )

sybase_min_client_severity sets the minimum client severity level.

参数

severity

返回值

没有返回值。

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

参见

  • sybase_min_server_severity

sybase_min_error_severity

Sets minimum error severity

Warning

This function was REMOVED in PHP 7.0.0.

说明

void sybase_min_error_severity ( int $severity )

sybase_min_error_severity sets the minimum error severity level.

参数

severity

返回值

没有返回值。

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

参见

  • sybase_min_message_severity

sybase_min_message_severity

Sets minimum message severity

Warning

This function was REMOVED in PHP 7.0.0.

说明

void sybase_min_message_severity ( int $severity )

sybase_min_message_severity sets the minimum message severity level.

参数

severity

返回值

没有返回值。

注释

Note: 此函数仅适用于对 Sybase 使用 DB 库接口,而不适用于 CT 库。

参见

  • sybase_min_error_severity

sybase_min_server_severity

Sets minimum server severity

Warning

This function was REMOVED in PHP 7.0.0.

说明

void sybase_min_server_severity ( int $severity )

sybase_min_server_severity sets the minimum server severity level.

参数

severity

返回值

没有返回值。

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

参见

  • sybase_min_client_severity

sybase_num_fields

Gets the number of fields in a result set

Warning

This function was REMOVED in PHP 7.0.0.

说明

int sybase_num_fields ( resource $result )

sybase_num_fields returns the number of fields in a result set.

参数

result

返回值

Returns the number of fields as an integer.

参见

  • sybase_query
  • sybase_fetch_field
  • sybase_num_rows

sybase_num_rows

Get number of rows in a result set

Warning

This function was REMOVED in PHP 7.0.0.

说明

int sybase_num_rows ( resource $result )

sybase_num_rows returns the number of rows in a result set.

参数

result

返回值

Returns the number of rows as an integer.

参见

  • sybase_num_fields
  • sybase_query
  • sybase_fetch_row

sybase_pconnect

Open persistent Sybase connection

Warning

This function was REMOVED in PHP 7.0.0.

说明

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

sybase_pconnect acts very much like sybase_connect with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (sybase_close will not close links established by sybase_pconnect).

This type of links is therefore called 'persistent'.

参数

servername
The servername argument has to be a valid servername that is defined in the 'interfaces' file.

username
Sybase user name

password
Password associated with username.

charset
Specifies the charset for the connection

appname
Specifies an appname for the Sybase connection. This allow you to make separate connections in the same script to the same database. This may come handy when you have started a transaction in your current connection, and you need to be able to do a separate query which cannot be performed inside this transaction.

返回值

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

参见

  • sybase_connect

sybase_query

Sends a Sybase query

Warning

This function was REMOVED in PHP 7.0.0.

说明

mixed sybase_query ( string $query [, resource $link_identifier ] )

sybase_query sends a query to the currently active database on the server that's associated with the specified link identifier.

参数

query

link_identifier
If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if sybase_connect was called, and use it.

返回值

Returns a positive Sybase result identifier on success, FALSE on error, or TRUE if the query was successful but didn't return any columns.

参见

  • sybase_select_db
  • sybase_connect

sybase_result

Get result data

Warning

This function was REMOVED in PHP 7.0.0.

说明

string sybase_result ( resource $result , int $row , mixed $field )

Returns the contents of the cell at the row and offset in the specified Sybase result set.

When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than sybase_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.

Recommended high-performance alternatives: sybase_fetch_row, sybase_fetch_array and sybase_fetch_object.

参数

result

row

field
The field argument can be the field's offset, or the field's name, or the field's table dot field's name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name.

返回值

sybase_result returns the contents of one cell from a Sybase result set.

sybase_select_db

Selects a Sybase database

Warning

This function was REMOVED in PHP 7.0.0.

说明

bool sybase_select_db ( string $database_name [, resource $link_identifier ] )

sybase_select_db sets the current active database on the server that's associated with the specified link identifier.

Every subsequent call to sybase_query will be made on the active database.

参数

database_name

link_identifier
If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if sybase_connect was called, and use it.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

参见

  • sybase_connect
  • sybase_pconnect
  • sybase_query

sybase_set_message_handler

Sets the handler called when a server message is raised

Warning

This function was REMOVED in PHP 7.0.0.

说明

bool sybase_set_message_handler ( callable $handler [, resource $link_identifier ] )

sybase_set_message_handler sets a user function to handle messages generated by the server. You may specify the name of a global function, or use an array to specify an object reference and a method name.

参数

handler
The handler expects five arguments in the following order: message number, severity, state, line number and description. The first four are integers. The last is a string. If the function returns FALSE, PHP generates an ordinary error message.

link_identifier
If the link identifier isn't specified, the last opened link is assumed.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 sybase_set_message_handler callback function

<?php
    function msg_handler($msgnumber, $severity, $state, $line, $text)
    {
        var_dump($msgnumber, $severity, $state, $line, $text);
    }

    sybase_set_message_handler('msg_handler');
?>

示例 #2 sybase_set_message_handler callback to a class

<?php
    class Sybase {
        function handler($msgnumber, $severity, $state, $line, $text)
        {
            var_dump($msgnumber, $severity, $state, $line, $text);
        }
    }

    $sybase= new Sybase();
    sybase_set_message_handler(array($sybase, 'handler'));
?>

示例 #3 sybase_set_message_handler unhandled messages

<?php
    // Return FALSE from this function to indicate you can't handle
    // this. The error is printed out as a warning, the way you're used
    // to it if there is no handler installed.
    function msg_handler($msgnumber, $severity, $state, $line, $text)
    {
        if (257 == $msgnumber) {
            return false;
        }
        var_dump($msgnumber, $severity, $state, $line, $text);
    }

    sybase_set_message_handler('msg_handler');
?>

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

sybase_unbuffered_query

Send a Sybase query and do not block

Warning

This function was REMOVED in PHP 7.0.0.

说明

resource sybase_unbuffered_query ( string $query , resource $link_identifier [, bool $store_result ] )

sybase_unbuffered_query sends a query to the currently active database on the server that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if sybase_connect was called, and use it.

Unlike sybase_query, sybase_unbuffered_query reads only the first row of the result set. sybase_fetch_array and similar function read more rows as needed. sybase_data_seek reads up to the target row. The behavior may produce better performance for large result sets.

sybase_num_rows will only return the correct number of rows if all result sets have been read. To Sybase, the number of rows is not known and is therefore computed by the client implementation.

Note:

If you don't read all of the resultsets prior to executing the next query, PHP will raise a warning and cancel all of the pending results. To get rid of this, use class="function">sybase_free_result which will cancel pending results of an unbuffered query.

参数

query

link_identifier

store_result
The optional store_result can be FALSE to indicate the resultsets shouldn't be fetched into memory, thus minimizing memory usage which is particularly interesting with very large resultsets.

返回值

Returns a positive Sybase result identifier on success, or FALSE on error.

范例

示例 #1 sybase_unbuffered_query example

<?php

$dbh = sybase_connect('SYBASE', '', '');
$q = sybase_unbuffered_query('select firstname, lastname from huge_table', $dbh, false);
sybase_data_seek($q, 10000);
$i = 0;

while ($row = sybase_fetch_row($q)) {
    echo $row[0], ' ', $row[1], '<br />';
    if ($i++ > 40000) {
        break;
    }
}

sybase_free_result($q);
sybase_close($dbh);

?>

注释

Note: 此函数仅适用于对 Sybase 使用 CT 库接口,而不适用于 DB 库。

参见

  • sybase_query

目录