Adaptive Server Enterprise Programmers Guide For PHP en
Adaptive Server Enterprise Programmers Guide For PHP en
3 Glossary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The SAP Adaptive Server Enterprise extension module for the PHP scripting language allows PHP developers
to execute queries against an SAP ASE database.
The extension module for PHP is a vendor-specific database interface driver that executes queries against an
SAP ASE database. The open source programming language, PHP (Hypertext Preprocessor) provides the
ability to retrieve information from common databases. The SAP ASE extension module for the PHP scripting
language includes the necessary PHP APIs to enable PHP developers to write standalone scripts to execute
queries against an SAP ASE database.
The extension module for PHP has been tested against the command line PHP implementation. Usage of the
extension, such as a CGI module in a Web server, is beyond the scope of SAP testing.
Required Components
Access to an SAP ASE database using the PHP programming language requires the following components:
Version Requirements
For information about platform support, see the Software Developers Kit and Open Server Installation Guide for
your platform.
● SAP ASE – version 15.7 or later. The PHP driver has been developed and tested against version 15.7 and
16.0. However, the driver can connect to SAP ASE version earlier than 15.7.
● PHP installation – version 5.3.6 or 5.6.5.
● CT-Library from Open Client SDK – version 15.7
● DBCAPI — SAP recommends that you use the DBCAPI library and the PHP driver from the same SDK
installation.
The extension module for PHP is a component you can install through the Sybase Installer.
The extension module for PHP is an optional installation component when you choose Custom as the
installation type. The extension is installed by default if the installation type you choose is Typical or Full.
This is an overview of the extension module installation; for complete installation instructions, see the SAP
Open Server and SDK for SAP ASE Installation Guide for your platform.
● Pre-installation requirements:
○ PHP installation 5.3.6 or 5.6.5 – 64-bit only.
○ Open Client SDK is required. The DBCAPI library is included in the Open Client SDK and is installed
together with the core Open Client (CT-Library).
Do not install DBCAPI as part of the driver.
● The extension module for PHP is installed as a PHP extension in a dynamic library.
The Sybase installer installs the extension module into the Open Client (CT-Library) directory as one
shared library called sybaseasephp.so.
● These files are installed with the extension module:
$SYBASE/$SYBASE_OCS/php/php<version>_64/lib/sybaseasephp.so
$SYBASE/$SYBASE_OCS/php/php<version>_64/devlib/sybaseasephp.so
$SYBASE/$SYBASE_OCS/sample/php/README
$SYBASE/$SYBASE_OCS/sample/php/firstapp.php
$SYBASE/$SYBASE_OCS/sample/php/dsnconnect.php
Related Information
Configure your environment to locate the extension module and OCS installations.
Environment Variables
To successfully use the extension module, set Sybase environment variables in the environment in which you
run the PHP executable. At a minimum, you must set the $SYBASE and $SYBASE_OCS environment variables.
Set the <LD_LIBRARY_PATH> variable to point to the correct location under the $SYBASE/$SYBASE_OCS/lib
directory. The extension module loads the DBCAPI library from this location.
PHP Configuration
A system administrator can copy the extension module into a different extension specific directory and load
the extension module from the directory by modifying the php.ini file, for example:
Extension Libraries
When executing php -m you should see the sybaseasephp extension listed among the extensions active in
the PHP installation.
Note
You need not place all extension libraries of a particular PHP installation in the same directory.
For information about running the sample scripts, see the README file located in the same directory. Also see
the Software Developers Kit and Open Server Installation Guide for platform installation information.
● firstapp.php – a simple example program that connects to a server, sends a select query, and prints the
rows.
● dsnconnect.php – a simple example program that connects to a server using a DSN connection string. It
optionally prints out the servername, account, and the current database.
When you call either sybase_connect() or sybase_pconnect() APIs using only the servername
parameter, servername must contain a valid DSN (data source name) string. The data source name is a
semicolon (;) separated string of name=value parts as explained as follows:
1. Name – a case-insensitive value that can be delimited by an equal sign (=) or semicolon (;). An attribute
can have multiple synonyms. For example, server and servername refer to the same attribute.
2. Equals sign (=) – indicates the start of the value to be assigned to the Name. If there is no equals sign, the
Name is assumed to be of boolean type with a value of true.
3. Value – a string that is terminated by a semicolon (;). Use a backslash (\) if a semicolon or another back
slash is present in the value. Values can be of type boolean, integer, or string. Valid values for Boolean types
are true, false, on, off, 1, and 0.
Note
If a boolean name is present without a value, the Boolean type must be set to true.
For example:
Username=name;Password=pwd;Timeout=10
Related Information
The table lists the valid attribute names and values for the dsn keyword argument.
This option affects <> NULL> and <is not NULL> behavior in
a similar fashion.
ChainXacts If true, SAP ASE uses chained transaction behavior, that is, Boolean value.
each server command is considered to be a distinct transac
The default is false.
tion.
Confidentiality Whether data encryption service is performed on the connec Boolean value.
tion.
The default is false.
CredentialDelegation Determines whether to allow the server to connect to a second Boolean value.
server with the user’s delegated credentials.
The default is false.
DetectReplay Determines whether the connection’s security mechanism de Boolean value.
tects replayed transmissions.
The default is false.
DetectOutOfSequence Determines whether the connection’s security mechanism de Boolean value.
tects transmissions that arrive out of sequence.
The default is false.
Integrity Determines whether the connection’s security mechanism per Boolean value.
forms data integrity checking.
The default is false.
Interfaces The path and name of the interfaces file. String value.
Keytab The name and path to the file from which a connection’s secur String value.
ity mechanism reads the security key to go with the
The default is NULL,
<username> value.
that is, the user must
have established cre
dentials before con
necting.
Locale Determines which language and character set to use for mes String value.
sages, datatype conversions, and datetime formats.
Language Determines which language set to use for messages, datatype String value.
conversions, and datetime formats.
MaxConnect Specifies the maximum number of simultaneously open con Integer value.
nections that a context may have.
Default value is 25.
Negative and zero val
ues are not allowed.
MutualAuthentication Determines whether the server is required to authenticate it Boolean value.
self to the client.
The default is false.
NetworkAuthentication Determines whether the connection’s security mechanism per Boolean value.
forms network-based user authentication.
The default is false.
Password Specifies the password used to log in to the server. String value.
PasswordEncryption Determines whether the connection uses asymmetrical pass Boolean value.
word encryption.
The default is false.
SecurityMechanism Specifies the name of the network security mechanism that String value.
performs security services for the connection.
The default value de
pends on security
driver configuration.
Server Specifies the name of the server to which you are connected. String value.
Servername
ServerPrincipalName Specifies the network security principal name for the server to String value.
which a connection is opened.
The default is NULL,
which means that the
connection assumes
the server principal
name is the same as
its <ServerName>
value.
UID Specifies the name used to log in to the server. String value.
User
Username
The dsnconnect.php sample program connects to a server using a DSN connection string. It optionally prints
the server name, the user account, and the current database.
Related Information
1.4.1 sybase_affected_rows
Returns the number of rows affected by the last INSERT, UPDATE, or DELETE query on the connection referred
to by $conn.
This function is typically used for INSERT, UPDATE, or DELETE statements. For SELECT statements, use the
sybase_num_rows() function instead.
Syntax
Parameters
$conn
the connection resource returned by a connection opening function. If the connection
resource isn't specified, the most recently opened connection is used.
The number of rows affected by the last INSERT, UPDATE, or DELETE query.
1.4.2 sybase_close
Closes a connection.
Syntax
Parameters
$conn
the connection resource returned by a connection opening function. If the connection
resource is not specified, the most recently opened connection is closed.
Returns
TRUE on success.
FALSE on failure.
1.4.3 sybase_connect
Syntax
Parameters
$servername
when sybase_connect() is called with more than this parameter, then $servername
contains a server defined in the relevant Sybase directory service. When
sybase_connect() is called with only this parameter, then $servername contains a
valid DSN connection string of syntax: param1=val1;param2=val2;...
$username
the user account used to log in to SAP ASE server.
$password
the password of the user account with which to log in to SAP ASE server.
Returns
FALSE on failure.
1.4.4 sybase_data_seek
Moves the internal row pointer on the result set associated with the result identifier to point to the specified
row number.
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query().
$row
Returns
1.4.5 sybase_fetch_array
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query()..
$result_type
the type of array to be returned. It accepts the following values to return arrays with:
Returns
Fetches one row of data from the result set associated with the specified result identifier in an associative
array.
Positions the internal pointer one row farther in the result set. A subsequent call to sybase_fetch_assoc()
returns the next row in the result set, or FALSE if there are no more rows.
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query().
Returns
1.4.7 sybase_fetch_field
Syntax
Parameters
$result
$field_offset
the field number (starting from 0) to retrieve information from. If the field offset is not
specified, the next field that is not yet retrieved by this function is used.
Returns
table string The table from which the column was taken.
1.4.8 sybase_fetch_object
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query().
$object
optionally, specify the type of object to be returned. The default object type is stdClass.
Returns
Returns an object with properties that correspond to the fetched row's field names.
1.4.9 sybase_fetch_row
Fetches one row of data from the result set associated with the specified result identifier in a numerical array.
It positions the internal pointer one row farther in the result set.
A subsequent call to sybase_fetch_row() returns the next row in the result set, or FALSE if there are no
more rows.
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query().
Returns
1.4.10 sybase_field_seek
Syntax
$result
the result resource that comes from a call to sybase_query().
$field_offset
the field offset (starting at 0).
Returns
1.4.11 sybase_free_result
Although result memory is automatically freed when the PHP script ends. SAP recommends, as a good
programming practice, that you free memory that is no longer needed.
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query().
Returns
Syntax
string sybase_get_last_message(void)
Parameters
None
Returns
1.4.13 sybase_get_last_status
Returns the last status result that was sent on the connection $conn.
Syntax
Parameters
$conn
the connection resource returned by a connection opening function.
The last status result that was sent on the connection $conn.
1.4.14 sybase_next_result
Returns a result set identifier pointing to the next result set on connection $conn.
Syntax
Parameters
$conn
the connection resource returned by a connection opening function.
Returns
1.4.15 sybase_num_fields
Syntax
$result
the result resource that comes from a call to sybase_query().
Returns
1.4.16 sybase_num_rows
Syntax
Parameters
$result
the result resource that comes from a call to sybase_query().
Returns
Note
If a persistent connection has been previously opened with the same arguments as this call, an identifier
for the existing connection gets returned instead of opening a new connection.
Syntax
Parameters
$servername
when sybase_connect() is called with more than this parameter, then $servername
contains a server defined in the relevant Sybase directory service. When
sybase_connect() is called with only this parameter, then $servername contains a
valid DSN connection string of syntax: param1=val1;param2=val2;...
$username
the name of the user account used to login to SAP ASE Server.
$password
the password of the user account used to login to SAP ASE Server.
Returns
FALSE – on failure.
Syntax
Parameters
$query
a string containing the query to be sent to the SAP ASE server.
$conn
the connection resource returned by a connection opening function. If the connection
resource is not specified, the most recently opened connection is used.
Returns
1.4.19 sybase_rpc_bind_param_ex
Syntax
$stmt
a statement identifier resource returned by a sybase_rpc_init() call.
$param_id
positional index of the stored procedure parameter to bind with. It starts with 0 for the
first parameter.
$var
reference to (address of) the PHP variable to be bound.
$type
the data type of the PHP variable that will be bound. One of: 'd' - double
'i' - integer
'b' - binary
's' - string
$is_null
an optional boolean indicating whether the variable contains a NULL or not.
$direction
optionally, one of: SASE_D_INPUT – for an input parameter (default).
Returns
1.4.20 sybase_rpc_execute
Executes the remote procedure call that was initialized with sybase_rpc_init() in $stmt.
Syntax
$stmt
a statement identifier resource returned by a sybase_rpc_init() call.
Returns
1.4.21 sybase_rpc_init
Returns a statement identifier pointing to the statement initialized for $procedure on connection $conn.
Syntax
Parameters
$conn
the connection resource returned by a connection opening function.
$procedure
the name of the remote (stored) procedure to be executed with
sybase_rpc_execute().
Returns
Sets the current active database on the server referred to by the connection resource.
Every subsequent call to sybase_query() is made on the active database of the current connection resource.
Syntax
Parameters
$database_name
the name of the database to use.
$conn
the connection resource returned by a connection opening function.
If the connection resource is
not specified, the most recently opened connection is used.
Returns
1.4.23 sybase_set_message_handler
Sets a user defined callback function that is called when either a client or a server message is received.
Syntax
$handler
the callback handler takes the following arguments:
int – message_number
int – severity
int – state
int – line_number
string – description
$msg_type
one of:
Note
$conn
the connection resource returned by a connection opening function.
If the connection resource is
not specified, the most recently opened connection is used.
Returns
1.4.24 sybase_unbuffered_query
Use sybase_fetch_array() and similar functions to read more rows as needed and use
sybase_data_seek() to jump to the target row.
Use sybase_num_rows() to return the correct number of rows when the complete result set has been read.
Parameters
$query
a string containing the query to be sent to SAP ASE server.
$conn
the connection resource returned by a connection opening function.
If the connection resource is not specified, the most recently opened connection is
used.
Returns
TRUE – query has been successful but no result set was returned.
1.4.25 sybase_use_result
Stores the result set of the last unbuffered query on connection $conn and returns a result set identifier
pointing to this stored result set.
Syntax
Parameters
$conn
the connection resource returned by a connection opening function.
The extension module options enabling security are currently not supported.
For a connection, use ocs.cfg to set directory and security properties. Edit libtcl.cfg to load security and
directory service drivers.
For more information, see Configuration Files in the Open Client and Open Server Configuration Guide for UNIX.
Multiversion concurrency control (MVCC) enables concurrent read-write operations, by allowing the server to
lock rows for writing in one session while granting access to unaltered versions of these rows in another
session, so that reads never wait for writes, and writes never wait for reads.
● Regular MVCC – uses in-memory row versioning, where all inserts, updates, and deletes are performed in
the in-memory row storage.
● On-disk multiversion concurrency control (on-disk MVCC) – stores row versions in a temporary database
specified when the database is created or altered.
The two types use slightly different parameters to create or alter the database. In addition to the standard
isolation levels offered by SAP ASE, SAP ASE uses three isolation levels specifically to enable multiversion
concurrency control, which are not part of the standard SQL:
● Statement snapshot
● Transaction snapshot
● Readonly statement snapshot
Related Information
ISOLATION_MODE is a connection-level property that is used to enable the MVCC feature by converting ANSI
isolation levels to snapshot isolation levels for MVCC- and on-disk MVCC-enabled tables.
Note
SAP ASE provides the following techniques to migrate applications to use snapshot isolation seamlessly,
and with minimal application changes. Perform these changes on the application in conjunction with any
necessary server-side changes. If you do not set the ISOLATION_MODE property, existing applications
default to run at ANSI isolation levels.
You can set the ISOLATION_MODE connection property for the client and map ANSI isolation levels to snapshot
isolation levels. When ISOLATION_MODE is set to snapshot, the isolation level maps as:
Once the ISOLATION_MODE connection property is set, the server overrides the set transaction
isolation command from the connection or system procedure, which avoids having to make application
changes to set isolation levels. For example, if a stored procedure sets the isolation level to ANSI isolation levels
0, 1, 2, or 3, but when using MVCC-enabled tables and the ISOLATION_MODE property is set, the ANSI isolation
level for the stored procedure is converted to the statement snapshot or transaction snapshot
isolation levels described above.
● default – the applications use the isolation levels specified by the application.
● snapshot – the application uses the snapshot isolation levels listed in the following table when it specifies
traditional ANSI isolation levels for MVCC-enabled tables.
● readonly_snapshot – the application uses the snapshot isolation levels listed in the following table when
it specifies traditional ANSI isolation levels for MVCC-enabled tables.
The IsolationMode= connection string property is supported for the scripting drivers and maps to the
CS_OPT_ISOLATION_MODE option. Valid values for this property are 0, 1, and 2.
Client-Library part of Open Client, a collection of routines for use in writing client applications. Client-Library
is designed to accommodate cursors and other advanced features in the Sybase product line.
CS-Library included with both the Open Client and Open Server products, a collection of utility routines
that are useful to both Client-Library and Server-Library applications.
CT-Library (CT-Lib API) is part of the Open Client suite and is required to let an scripting application
connect to Adaptive Server.
thread a path of execution through Open Server application and library code and the path’s
associated stack space, state information, and event handlers.
Transact-SQL an enhanced version of the database language SQL. Applications can use Transact-SQL to
communicate with Adaptive Server Enterprise.
Hyperlinks
Some links are classified by an icon and/or a mouseover text. These links provide additional information.
About the icons:
● Links with the icon : You are entering a Web site that is not hosted by SAP. By using such links, you agree (unless expressly stated otherwise in your
agreements with SAP) to this:
● The content of the linked-to site is not SAP documentation. You may not infer any product claims against SAP based on this information.
● SAP does not agree or disagree with the content on the linked-to site, nor does SAP warrant the availability and correctness. SAP shall not be liable for any
damages caused by the use of such content unless damages have been caused by SAP's gross negligence or willful misconduct.
● Links with the icon : You are leaving the documentation for that particular SAP product or service and are entering a SAP-hosted Web site. By using such
links, you agree that (unless expressly stated otherwise in your agreements with SAP) you may not infer any product claims against SAP based on this
information.
Example Code
Any software coding and/or code snippets are examples. They are not for productive use. The example code is only intended to better explain and visualize the syntax
and phrasing rules. SAP does not warrant the correctness and completeness of the example code. SAP shall not be liable for errors or damages caused by the use of
example code unless damages have been caused by SAP's gross negligence or willful misconduct.
Gender-Related Language
We try not to use gender-specific word forms and formulations. As appropriate for context and readability, SAP may use masculine word forms to refer to all genders.
SAP and other SAP products and services mentioned herein as well as
their respective logos are trademarks or registered trademarks of SAP
SE (or an SAP affiliate company) in Germany and other countries. All
other product and service names mentioned are the trademarks of their
respective companies.