Sybase Functions

Sybase Functions

sybase_affected_rows

Name

sybase_affected_rows — get number of affected rows in last query

Description

int sybase_affected_rows(int [link_identifier] );

Returns: The number of affected rows by the last query.

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. If the link identifier isn't specified, the last opened link is assumed.

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.

sybase_close

Name

sybase_close — close Sybase connection

Description

int sybase_close(int link_identifier);

Returns: true on success, false on error

sybase_close() closes the link to a Sybase database that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.

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(). See also: sybase_connect, sybase_pconnect.

sybase_connect

Name

sybase_connect — open Sybase server connection

Description

int sybase_connect(string servername, string username, string password);

Returns: A positive Sybase link identifier on success, or false on error.

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.

See also sybase_pconnect, sybase_close.

sybase_data_seek

Name

sybase_data_seek — move internal row pointer

Description

int sybase_data_seek(int result_identifier, int row_number);

Returns: true on success, false on failure

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

See also: sybase_data_seek.

sybase_fetch_array

Name

sybase_fetch_array — fetch row as array

Description

int sybase_fetch_array(int result);

Returns: An array that corresponds to the fetched row, or false if there are no more rows.

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.

For further details, also see sybase_fetch_row

sybase_fetch_field

Name

sybase_fetch_field — get field information

Description

object sybase_fetch_field(int result, int field_offset);

Returns an object containing field information.

sybase_fetch_field() can be used in order to obtain information about fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retreived by sybase_fetch_field() is retreived.

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 See also sybase_field_seek

sybase_fetch_object

Name

sybase_fetch_object — fetch row as object

Description

int sybase_fetch_object(int result);

Returns: An object with properties that correspond to the fetched row, or false if there are no more rows.

sybase_fetch_object() is similar to sybase_fetch_array, with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).

Speed-wise, the function is identical to sybase_fetch_array, and almost as quick as

sybase_fetch_row (the difference is insignificant).

See also: sybase_fetch-array and sybase_fetch-row.

sybase_fetch_row

Name

sybase_fetch_row — get row as enumerated array

Description

array sybase_fetch_row(int result);

Returns: An array that corresponds to the fetched row, or false if there are no more rows.

sybase_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Subsequent call to sybase_fetch_rows() would return the next row in the result set, or false if there are no more rows.

See also: sybase_fetch_array, sybase_fetch_object, sybase_data_seek, sybase_fetch_lengths, and sybase_result.

sybase_field_seek

Name

sybase_field_seek — set field offset

Description

int sybase_field_seek(int 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.

See also: sybase_fetch_field.

sybase_free_result

Name

sybase_free_result — free result memory

Description

int sybase_free_result(int 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, you may call sybase_free_result with the result identifier as an argument and the associated result memory will be freed.

sybase_num_fields

Name

sybase_num_fields — get number of fields in result

Description

int sybase_num_fields(int result);

sybase_num_fields() returns the number of fields in a result set.

See also: sybase_db_query, sybase_query, sybase_fetch_field, sybase_num_rows.

sybase_num_rows

Name

sybase_num_rows — get number of rows in result

Description

int sybase_num_rows(string result);

sybase_num_rows() returns the number of rows in a result set.

See also: sybase_db_query, sybase_query and, sybase_fetch_row.

sybase_pconnect

Name

sybase_pconnect — open persistent Sybase connection

Description

int sybase_pconnect(string servername, string username, string password);

Returns: A positive Sybase persistent link identifier on success, or false on error 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'.

sybase_query

Name

sybase_query — send Sybase query

Description

int sybase_query(string query, int link_identifier);

Returns: A positive Sybase result identifier on success, or false on error.

sybase_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.

See also: sybase_db_query, sybase_select_db, and sybase_connect.

sybase_result

Name

sybase_result — get result data

Description

int sybase_result(int result, int i, mixed field);

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

sybase_result() returns the contents of one cell from a Sybase result set. The field argument can be the field's offset, or the field's name, or the field's table dot field's name (fieldname.tablename). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name.

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.

sybase_select_db

Name

sybase_select_db — select Sybase database

Description

int sybase_select_db(string database_name, int link_identifier);

Returns: true on success, false on error

sybase_select_db() sets the current active database on the server that's associated with the specified 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.

Every subsequent call to sybase_query will be made on the active database. See also: sybase_connect, sybase_pconnect, and sybase_query