Developing Perl and PHP Applications - Db2ape90
Developing Perl and PHP Applications - Db2ape90
DB2 Version 9
for Linux, UNIX, and Windows
SC10-4234-00
DB2 ®
DB2 Version 9
for Linux, UNIX, and Windows
SC10-4234-00
Before using this information and the product it supports, be sure to read the general information under Notices.
Edition Notice
This document contains proprietary information of IBM. It is provided under a license agreement and is protected
by copyright law. The information contained in this publication does not include any product warranties, and any
statements provided in this manual should not be interpreted as such.
You can order IBM publications online or through your local IBM representative.
v To order publications online, go to the IBM Publications Center at www.ibm.com/shop/publications/order
v To find your local IBM representative, go to the IBM Directory of Worldwide Contacts at www.ibm.com/
planetwide
To order DB2 publications from DB2 Marketing and Sales in the United States or Canada, call 1-800-IBM-4YOU
(426-4968).
When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any
way it believes appropriate without incurring any obligation to you.
© Copyright International Business Machines Corporation 2006. All rights reserved.
US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract
with IBM Corp.
Contents
Part 1. Developing PHP Applications 1 db2_commit - Commits a transaction . . . . . 39
db2_conn_error - Returns a string containing the
SQLSTATE returned by the last connection
Chapter 1. Introduction to Developing attempt . . . . . . . . . . . . . . . 40
PHP Applications . . . . . . . . . . . 3 db2_conn_errormsg - Returns the last connection
Introduction to PHP application development for error message and SQLCODE value . . . . . 41
DB2 . . . . . . . . . . . . . . . . . 3 db2_connect - Returns a connection to a database 42
Setting up the PHP environment on Windows . . . 4 db2_pconnect - Returns a persistent connection to
Setting up the PHP environment on Linux or UNIX . 5 a database . . . . . . . . . . . . . . 45
db2_rollback - Rolls back a transaction . . . . 46
Chapter 2. Developing PHP Applications Statement functions . . . . . . . . . . . . 48
with ibm_db2 . . . . . . . . . . . . 7 db2_bind_param - Binds a PHP variable to an
Connecting to a DB2 database with PHP (ibm_db2) . 7 SQL statement parameter . . . . . . . . . 48
Retrieving database metadata (ibm_db2) . . . . . 8 db2_exec - Executes an SQL statement directly . 50
Executing XQuery expressions in PHP (ibm_db2) . . 10 db2_execute - Executes a prepared SQL statement 52
Executing a single SQL statement in PHP (ibm_db2) 11 db2_free_result - Frees resources associated with
Preparing and executing SQL statements in PHP a result set. . . . . . . . . . . . . . 54
(ibm_db2) . . . . . . . . . . . . . . . 12 db2_free_stmt - Frees resources associated with
Inserting large objects in PHP (ibm_db2) . . . . 14 the indicated statement resource . . . . . . 54
Fetching columns from result sets in PHP (ibm_db2) 15 db2_prepare - Prepares an SQL statement to be
Fetching rows from result sets in PHP (ibm_db2) . . 16 executed . . . . . . . . . . . . . . 55
Fetching large objects in PHP (ibm_db2) . . . . . 17 db2_stmt_error - Returns a string containing the
Managing transactions in PHP (ibm_db2) . . . . 17 SQLSTATE returned by an SQL statement . . . 57
Handling errors and warning messages (ibm_db2) 18 db2_stmt_errormsg - Returns a string containing
Calling stored procedures with OUT or INOUT the last SQL statement error message . . . . . 57
parameters in PHP (ibm_db2) . . . . . . . . 20 Fetch functions . . . . . . . . . . . . . 58
Calling stored procedures that return multiple result db2_fetch_array - Returns an array, indexed by
sets in PHP (ibm_db2) . . . . . . . . . . . 21 column position, representing a row in a result
set . . . . . . . . . . . . . . . . 58
db2_fetch_assoc - Returns an array, indexed by
Chapter 3. Developing PHP column name, representing a row in a result set . 60
Applications with PDO . . . . . . . . 23 db2_fetch_both - Returns an array, indexed by
Connecting to a DB2 database with PHP (PDO) . . 23 both column name and position, representing a
Executing a single SQL statement in PHP that row in a result set . . . . . . . . . . . 61
returns no result sets (PDO) . . . . . . . . . 24 db2_fetch_object - Returns an object with
Executing a single SQL statement in PHP that properties representing columns in the fetched
returns a result set (PDO). . . . . . . . . . 25 row . . . . . . . . . . . . . . . . 63
Preparing and executing SQL statements (PDO) . . 26 db2_fetch_row - Sets the result set pointer to the
Inserting large objects in PHP (PDO) . . . . . . 27 next row or requested row . . . . . . . . 64
Fetching columns from result sets in PHP (PDO) . . 28 db2_next_result - Requests the next result set
Fetching rows from result sets in PHP (PDO) . . . 29 from a stored procedure . . . . . . . . . 65
Fetching large objects in PHP (PDO) . . . . . . 31 db2_result - Returns a single column from a row
Managing transactions in PHP (PDO). . . . . . 32 in the result set . . . . . . . . . . . . 67
Handling errors and warnings in PHP (PDO) . . . 33 Metadata functions . . . . . . . . . . . . 68
Calling stored procedures with OUT or INOUT Database metadata functions . . . . . . . 68
parameters in PHP (PDO) . . . . . . . . . 33 Statement metadata functions . . . . . . . 90
Calling stored procedures that return multiple result
sets in PHP (PDO) . . . . . . . . . . . . 35 Chapter 5. PDO_ODBC Driver
Reference . . . . . . . . . . . . . 99
Chapter 4. ibm_db2 Extension PDO object methods . . . . . . . . . . . 99
Reference . . . . . . . . . . . . . 37 PDO::__construct - Creates a PDO instance
Connection functions . . . . . . . . . . . 37 representing a connection to a database . . . . 99
db2_autocommit - Returns or sets the PDO::beginTransaction - Initiates a transaction 101
AUTOCOMMIT state for a database connection . 37 PDO::commit - Commits a transaction . . . . 102
db2_close - Closes a database connection . . . 38
A third extension, Unified ODBC, has historically offered access to DB2 database
systems. It is not recommended that you write new applications with this
extension because ibm_db2 and PDO_ODBC both offer significant performance
and stability benefits over Unified ODBC. The ibm_db2 extension API makes
porting an application that was previously written for Unified ODBC almost as
easy as globally changing the odbc_ function name to db2_ throughout the source
code of your application.
Related tasks:
v “Setting up the PHP environment on Linux or UNIX” on page 5
v “Setting up the PHP environment on Windows” on page 4
Prerequisites:
Procedure:
Note: On Windows, the PDO_ODBC driver uses the Windows ODBC Driver
Manager to connect to database systems. To access DB2 database
systems with PDO_ODBC on Windows, you must install the IBM
DB2® Driver for ODBC and CLI.
v To enable the ibm_db2 extension:
extension=php_ibm_db2.dll
6. Enable PHP support in Apache HTTP Server 2.x by adding the following lines
to your httpd.conf file, in which phpdir refers to the PHP install directory:
LoadModule php5_module ’phpdir/php5apache2.dll’
AddType application/x-httpd-php .php
PHPIniDir ’phpdir’
7. Restart the Apache HTTP Server to enable the changed configuration.
Related concepts:
v “Introduction to PHP application development for DB2” on page 3
Related tasks:
v “Connecting to a DB2 database with PHP (ibm_db2)” on page 7
v “Connecting to a DB2 database with PHP (PDO)” on page 23
v “Setting up the PHP environment on Linux or UNIX” on page 5
Prerequisites:
v The Apache HTTP Server must be installed on your system.
v The DB2 development header files and libraries must be installed on your
system.
v The gcc compiler and other development packages including apache-devel,
autoconf, automake, bison, flex, gcc, and libxml2-devel package must be
installed on your system.
Procedure:
To compile PHP from source with support for DB2 on Linux or UNIX:
1. Download the latest version of the PHP tarball from http://www.php.net. The
latest version of PHP at the time of writing is PHP 5.1.2.
2. Untar the file by issuing the following command:
tar xjf php-5.1.2.tar.bz2
3. Change directories into the newly created php-5.1.2 directory.
4. Configure the makefile by issuing the configure command. Specify the
features and extensions you want to include in your custom version of PHP. A
typical configure command includes the following options:
./configure --enable-cli --disable-cgi --with-apxs2=/usr/sbin/apxs2
--with-zlib --with-pdo-odbc=ibm-db2
Related concepts:
v “Introduction to PHP application development for DB2” on page 3
Related tasks:
v “Connecting to a DB2 database with PHP (ibm_db2)” on page 7
v “Connecting to a DB2 database with PHP (PDO)” on page 23
v “Setting up the PHP environment on Windows” on page 4
Related reference:
v “PHP samples” in Samples Topics
Prerequisites:
Before connecting to a DB2 database through the ibm_db2 extension, you must set
up the PHP environment on your system and enable the ibm_db2 extension.
Procedure:
1. Create a connection to a DB2 database:
v To create a non-persistent connection to a DB2 database, call db2_connect()
with a database value that specifies either a cataloged database name or a
complete database connection string for a direct TCP/IP connection.
v To create a persistent connection to a DB2 database, call db2_pconnect() with
a database value that specifies either a cataloged database name or a complete
database connection string for a direct TCP/IP connection.
2. Check the value returned by db2_connect() or db2_pconnect.
v If the value returned by db2_connect() or db2_pconnect is FALSE, the
connection attempt failed. You can retrieve diagnostic information through
db2_conn_error() and db2_conn_errormsg().
v If the value returned by db2_connect() or db2_pconnect is not FALSE, the
connection attempt succeeded. You can use the connection resource to create,
update, delete, or retrieve data with other ibm_db2 functions.
When you create a connection by calling db2_pconnect() , PHP ignores any calls to
db2_close() for the specified connection resource and keeps the connection to the
database open for subsequent PHP scripts.
Related reference:
v “db2_pconnect - Returns a persistent connection to a database” on page 45
v “db2_close - Closes a database connection” on page 38
v “db2_conn_error - Returns a string containing the SQLSTATE returned by the
last connection attempt” on page 40
v “db2_conn_errormsg - Returns the last connection error message and SQLCODE
value” on page 41
Prerequisites:
v You must set up the PHP environment on your system and enable the ibm_db2
extension.
v You must have a connection resource returned from db2_connect() or
db2_pconnect().
Procedure:
1. Call the function that returns the metadata which you require:
db2_client_info()
Returns metadata about the DB2 client software and configuration.
db2_column_privileges()
Lists the columns and associated privileges for a table.
db2_columns()
Lists the columns and associated metadata for a table.
db2_foreign_keys()
Lists the foreign keys for a table.
db2_primary_keys()
Lists the primary keys for a table.
db2_procedure_columns()
Lists the parameters for one or more stored procedures.
db2_procedures()
Lists the stored procedures registered in the database.
db2_server_info()
Returns metadata about the database management system software and
configuration.
db2_special_columns()
Lists the unique row identifiers for a table.
db2_statistics()
Lists the indexes and statistics for a table.
db2_table_privileges()
Lists tables and their associated privileges in the database.
Related tasks:
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Related reference:
v “db2_foreign_keys - Returns a result set listing the foreign keys for a table” on
page 73
v “db2_primary_keys - Returns a result set listing primary keys for a table” on
page 74
v “db2_procedure_columns - Returns a result set listing stored procedure
parameters” on page 76
v “db2_procedures - Returns a result set listing the stored procedures registered in
a database” on page 78
v “db2_server_info - Returns an object with properties that describe the DB2
database management system” on page 79
v “db2_special_columns - Returns a result set listing the unique row identifier
columns for a table” on page 83
v “db2_statistics - Returns a result set listing the index and statistics for a table”
on page 85
v “db2_table_privileges - Returns a result set listing the tables and associated
privileges in a database” on page 87
v “db2_tables - Returns a result set listing the tables and associated metadata in a
database” on page 88
v “db2_client_info - Returns an object with properties that describe the DB2
database client” on page 68
v “db2_column_privileges - Returns a result set listing the columns and associated
privileges for a table” on page 70
v “db2_columns - Returns a result set listing the columns and associated metadata
for a table” on page 71
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Restrictions:
To avoid the security threat of injection attacks, db2_exec() should only be used to
execute SQL statements composed of static strings. Interpolation of PHP variables
representing user input into the XQuery expression can expose your application to
injection attacks.
Procedure:
1. Call db2_exec() with the following arguments:
a. The connection resource;
b. A string containing the SQL statement, including the XQuery expression.
The XQuery expression needs to be wrapped in a XMLQUERY clause in the
SQL statement.
c. (Optional): an array containing statement options
DB2_ATTR_CASE
For compatibility with database systems that do not follow the SQL
standard, this option sets the case in which column names will be
returned to the application. By default, the case is set to
DB2_CASE_NATURAL, which returns column names as they are
returned by DB2. You can set this parameter to DB2_CASE_LOWER
to force column names to lower case, or to DB2_CASE_UPPER to
force column names to upper case.
DB2_ATTR_CURSOR
This option sets the type of cursor that ibm_db2 returns for result
sets. By default, ibm_db2 returns a forward-only cursor
(DB2_FORWARD_ONLY) which returns the next row in a result set
for every call to db2_fetch_array(), db2_fetch_assoc(),
db2_fetch_both(), db2_fetch_object(), or db2_fetch_row(). You can
set this parameter to DB2_SCROLLABLE to request a scrollable
cursor so that the ibm_db2 fetch functions accept a second
argument specifying the absolute position of the row that you want
to access within the result set .
2. Check the value returned by db2_exec():
v If the value is FALSE, the SQL statement failed. You can retrieve diagnostic
information through the db2_stmt_error() and db2_stmt_errormsg()
functions.
v If the value is not FALSE, the SQL statement succeeded and returned a
statement resource that can be used in subsequent function calls related to
this query.
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Restrictions:
To avoid the security threat of SQL injection attacks, db2_exec() should only be
used to execute SQL statements composed of static strings. Interpolation of PHP
variables representing user input into the SQL statement can expose your
application to SQL injection attacks.
Procedure:
1. Call db2_exec() with the following arguments:
a. The connection resource;
b. A string containing the SQL statement;
c. (Optional): an array containing statement options
DB2_ATTR_CASE
For compatibility with database systems that do not follow the SQL
standard, this option sets the case in which column names will be
returned to the application. By default, the case is set to
DB2_CASE_NATURAL, which returns column names as they are
returned by DB2. You can set this parameter to DB2_CASE_LOWER
to force column names to lower case, or to DB2_CASE_UPPER to
force column names to upper case.
DB2_ATTR_CURSOR
This option sets the type of cursor that ibm_db2 returns for result
sets. By default, ibm_db2 returns a forward-only cursor
(DB2_FORWARD_ONLY) which returns the next row in a result set
for every call to db2_fetch_array(), db2_fetch_assoc(),
db2_fetch_both(), db2_fetch_object(), or db2_fetch_row(). You can
set this parameter to DB2_SCROLLABLE to request a scrollable
cursor so that the ibm_db2 fetch functions accept a second
argument specifying the absolute position of the row that you want
to access within the result set .
2. Check the value returned by db2_exec():
v If the value is FALSE, the SQL statement failed. You can retrieve diagnostic
information through the db2_stmt_error() and db2_stmt_errormsg()
functions.
If the SQL statement selected rows using a scrollable cursor, or inserted, updated,
or deleted rows, you can call db2_num_rows() to return the number of rows that the
statement returned or affected. If the SQL statement returned a result set, you can
begin fetching rows.
Related tasks:
v “Fetching columns from result sets in PHP (ibm_db2)” on page 15
v “Fetching large objects in PHP (ibm_db2)” on page 17
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_exec - Executes an SQL statement directly” on page 50
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Restrictions:
You can only use parameter markers as a place holder for column or predicate
values. The SQL compiler would be unable to create an access plan for a statement
that used parameter markers in place of column names, table names, or other SQL
identifiers.
Procedure:
Example:
$sql = "SELECT firstnme, lastname FROM employee WHERE bonus > ? AND bonus < ?";
$stmt = db2_prepare($conn, $sql);
if (!$stmt) {
// Handle errors
}
db2_execute($stmt);
// Process results
If you execute a prepared statement that returns one or more result sets, you can
begin retrieving rows from the statement resource by calling the
db2_fetch_array() , db2_fetch_assoc(), db2_fetch_both(), db2_fetch_object(), or
db2_fetch_row() functions.
Related reference:
v “db2_bind_param - Binds a PHP variable to an SQL statement parameter” on
page 48
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Procedure:
Example:
$stmt = db2_prepare($conn, "INSERT INTO animal_pictures(picture) VALUES (?)");
$picture = "/opt/albums/spook/grooming.jpg";
$rc = db2_bind_param($stmt, 1, "picture", DB2_PARAM_FILE);
$rc = db2_execute($stmt);
Related tasks:
v “Fetching large objects in PHP (ibm_db2)” on page 17
Prerequisites:
v You must set up the PHP environment on your system and enable the ibm_db2
extension.
v You must have a statement resource returned from db2_exec() or db2_execute()
with one or more associated result sets.
Procedure:
1. Call the db2_fetch_row() function to advance the cursor to the next row in the
result set. The first time you call a fetch function for a given result set advances
the cursor to the first row of the result set. If you requested a scrollable cursor,
you can also specify the number of the row in the result set that you want to
retrieve.
2. Check the result returned by db2_fetch_row(). If the result is FALSE, there are
no more rows in the result set.
3. Call the db2_result() function to retrieve the value from the requested column
by passing either an integer representing the position of the column in the row
(starting with 0 for the first column), or a string representing the name of the
column.
Example:
<?php
$sql = ’SELECT name, breed FROM animals WHERE weight < ?’;
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(10));
while (db2_fetch_row($stmt)) {
$name = db2_result($stmt, 0);
$breed = db2_result($stmt, ’BREED’);
print "$name $breed";
}
?>
Related reference:
v “db2_fetch_row - Sets the result set pointer to the next row or requested row”
on page 64
v “db2_result - Returns a single column from a row in the result set” on page 67
Prerequisites:
v You must set up the PHP environment on your system and enable the ibm_db2
extension.
v You must have a statement resource returned from db2_exec() or db2_execute()
with one or more associated result sets.
Procedure:
Call the ibm_db2 fetch function that returns the data from the row in the format
you prefer:
db2_fetch_array()
Returns an array containing the data corresponding to the columns of the
row indexed by column position starting at 0
db2_fetch_assoc()
Returns an array containing the data corresponding to the columns of the
row indexed by column name.
db2_fetch_both()
Returns an array containing the data corresponding to the columns of the
row indexed by both column name and by column position starting at 0.
db2_fetch_object()
Returns an object containing the data from the row. The object holds
properties matching the column names of the row which, when accessed,
return the corresponding values of the columns.
You must pass the statement resource as the first argument. If you requested a
scrollable cursor when you executed db2_exec() or db2_prepare(), you can pass an
absolute row number as the second argument. With the default forward-only
cursor, each call to a fetch method returns the next row in the result set. You can
continue fetching rows until the fetch method returns FALSE, which signifies that
you have reached the end of the result set.
Example:
$stmt = db2_exec($conn, "SELECT firstnme, lastname FROM employee");
while ($row = db2_fetch_object($stmt)) {
print "Name: <p>{$row->FIRSTNME} {$row->LASTNAME}</p>";
}
Related tasks:
v “Fetching large objects in PHP (ibm_db2)” on page 17
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_fetch_array - Returns an array, indexed by column position, representing a
row in a result set” on page 58
v “db2_fetch_assoc - Returns an array, indexed by column name, representing a
row in a result set” on page 60
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Procedure:
Example:
$stmt = db2_prepare($conn, "SELECT name, picture FROM animal_pictures");
$picture = fopen("/opt/albums/spook/grooming.jpg", "wb");
$rc = db2_bind_param($stmt, 1, "nickname", DB2_CHAR, 32);
$rc = db2_bind_param($stmt, 2, "picture", DB2_PARAM_FILE);
$rc = db2_execute($stmt);
$rc = db2_fetch_object($stmt);
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
You must use a regular connection created with db2_connect() to control database
transactions in PHP. Persistent connections always use autocommit mode.
Procedure:
To begin a transaction:
1. Create a database connection using the "AUTOCOMMIT" => DB2_AUTOCOMMIT_OFF
setting in the db2_connect() options array. You can also turn autocommit off
for an existing connection resource by calling db2_autocommit($conn,
DB2_AUTOCOMMIT_OFF). Calling db2_autocommit() requires additional
communication from PHP to the database management system and may affect
the performance of your PHP scripts.
2. Issue one or more SQL statements within the scope of the database transaction
using the connection resource for which transactions have been enabled.
3. Commit or rollback the transaction:
v To commit the transaction, call db2_commit().
v To rollback the transaction, call db2_rollback().
4. (Optional): Return the database connection to autocommit mode by calling
db2_autocommit($conn, DB2_AUTOCOMMIT_ON). If you issue another SQL
statement without returning the database connection to autocommit mode, you
begin a new transaction that will require a commit or rollback.
If you issue SQL statements in a transaction and the script ends without explicitly
committing or rolling back the transaction, the ibm_db2 extension automatically
rolls back any work performed in the transaction.
Example:
$conn = db2_connect(’SAMPLE’, ’db2inst1’, ’ibmdb2’, array(
’AUTOCOMMIT’ => DB2_AUTOCOMMIT_ON));
Related reference:
v “db2_autocommit - Returns or sets the AUTOCOMMIT state for a database
connection” on page 37
v “db2_commit - Commits a transaction” on page 39
v “db2_rollback - Rolls back a transaction” on page 46
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Procedure:
1. Check the value returned from the ibm_db2 function to ensure the function
returned successfully. If the function can return the value 0, such as
db2_num_rows(), you must explicitly test whether the value was FALSE using
PHP’s === operator.
2. If the function returned FALSE instead of the connection resource, statement
resource, or numeric value you expected, call the ibm_db2 error handling
function appropriate to the application context and the needs of your
application:
Connection errors
To retrieve the SQLSTATE returned by the last connection attempt, call
db2_conn_error(). To retrieve a descriptive error message appropriate
for an application error log, call db2_conn_errormsg().
$connection = db2_connect($database, $user, $password);
if (!$connection) {
$this->state = db2_conn_error();
return false;
}
SQL errors (executing SQL statements directly and fetching results)
To retrieve the SQLSTATE returned by the last attempt to prepare or
execute an SQL statement, or to fetch a result from a result set, call
db2_stmt_error(). To retrieve a descriptive error message appropriate
for an application error log, call db2_stmt_errormsg().
$stmt = db2_prepare($connection, "DELETE FROM employee
WHERE firstnme = ?");
if (!$stmt) {
$this->state = db2_stmt_error();
return false;
}
SQL errors (executing prepared statements)
If db2_prepare() returned successfully, but a subsequent call to
db2_execute() fails, call db2_stmt_error() or db2_stmt_errormsg() and
pass the resource returned from the call to db2_prepare() as the
argument.
$success = db2_execute($stmt, array(’Dan’);
if (!$success) {
$this->state = db2_stmt_error($stmt);
return $false;
}
3. To avoid the possibility of security vulnerabilities resulting from directly
displaying the raw SQLSTATE returned from the database, and to offer a better
overall user experience in your Web application, use a switch structure to
recover from known error states or return custom error messages.
switch($this->state):
case ’22001’:
// More data than allowed for the defined column
$message = "You entered too many characters for this value.";
break;
Prerequisites:
You must set up the PHP environment on your system and enable the ibm_db2
extension.
Procedure:
Example:
$sql = ’CALL match_animal(?, ?)’;
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt);
Related reference:
v “db2_bind_param - Binds a PHP variable to an SQL statement parameter” on
page 48
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Prerequisites:
v You must set up the PHP environment on your system and enable the ibm_db2
extension.
v You must have a statement resource returned from calling a stored procedure
with db2_exec() or db2_execute().
Procedure:
Example:
$stmt = db2_exec($conn, ’CALL multiResults()’);
Related reference:
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_next_result - Requests the next result set from a stored procedure” on page
65
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Prerequisites:
You must set up the PHP 5.1 or higher environment on your system and enable
the PDO and PDO_ODBC extensions.
Procedure:
1. Create a connection to the DB2 database by calling the PDO constructor within
a try{} block. Pass a DSN value that specifies odbc: for the PDO_ODBC
extension, followed by either a cataloged database name or a complete database
connection string for a direct TCP/IP connection.
v (Windows): By default, PDO_ODBC uses Windows ODBC Driver Manager
connection pooling to minimize connection resources and improve
connection performance.
v (Linux and UNIX): PDO_ODBC offers persistent connections if you pass
array(PDO::ATTR_PERSISTENT => TRUE) as the fourth argument to the PDO
constructor.
2. (Optional): Set error handling options for the PDO connection in the fourth
argument to the PDO constructor:
v by default, PDO sets an error message that can be retrieved through
PDO::errorInfo() and an SQLCODE that can be retrieved through
PDO::errorCode() when any error occurs; to request this mode explicitly, set
PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT
v to issue a PHP E_WARNING when any error occurs, in addition to setting the
error message and SQLCODE, set PDO::ATTR_ERRMODE =>
PDO::ERRMODE_WARNING
v to throw a PHP exception when any error occurs, set PDO::ATTR_ERRMODE =>
PDO::ERRMODE_EXCEPTION
3. Catch any exception thrown by the try{} block in a corresponding catch {}
block.
try {
$connection = new PDO("odbc:SAMPLE", "db2inst1", "ibmdb2", array(
PDO::ATTR_PERSISTENT => TRUE,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
}
catch (Exception $e) {
echo($e->getMessage());
}
Related reference:
v “PDO::__construct - Creates a PDO instance representing a connection to a
database” on page 99
v “PDO::errorCode - Fetch the SQLSTATE associated with the last operation on the
database handle” on page 102
v “PDO::errorInfo - Fetch extended error information associated with the last
operation on the database handle” on page 103
Prerequisites:
You must set up the PHP environment on your system and enable the PDO_ODBC
extension.
Restrictions:
To avoid the security threat of SQL injection attacks, PDO::exec() should only be
used to execute SQL statements composed of static strings. Interpolation of PHP
variables representing user input into the SQL statement can expose your
application to SQL injection attacks.
Procedure:
Example:
$conn = new PDO(’odbc:SAMPLE’, ’db2inst1’, ’ibmdb2’);
$result = $conn->exec(’SET SCHEMA myapp’);
if ($result === FALSE) {
print "Failed to set schema: " . $conn->errorMsg();
}
Related tasks:
Related reference:
v “PDO::exec - Execute an SQL statement and return the number of affected rows”
on page 104
Prerequisites:
You must set up the PHP environment on your system and enable the PDO_ODBC
extension.
Restrictions:
To avoid the security threat of SQL injection attacks, PDO::query() should only be
used to execute SQL statements composed of static strings. Interpolation of PHP
variables representing user input into the SQL statement can expose your
application to SQL injection attacks.
Procedure:
Example:
$conn = new PDO(’odbc:SAMPLE’, ’db2inst1’, ’ibmdb2’);
$result = $conn->query(’SELECT firstnme, lastname FROM employee’);
if (!$result) {
print "<p>Could not retrieve employee list: " . $conn->errorMsg(). "</p>";
}
while ($row = $conn->fetch()) {
print "<p>Name: {$row[0] $row[1]}</p>";
}
Related tasks:
Related reference:
v “PDO::query - Executes an SQL statement, returning a result set as a
PDOStatement object” on page 108
Prerequisites:
You must set up the PHP environment on your system and enable the PDO_ODBC
extension.
Restrictions:
v You can only use parameter markers as a place holder for column or predicate
values. The SQL compiler would be unable to create an access plan for a
statement that used parameter markers in place of column names, table names,
or other SQL identifiers.
v You cannot use both question mark parameter markers (?) and named parameter
markers (:name) in the same SQL statement.
Procedure:
Example:
$sql = "SELECT firstnme, lastname FROM employee WHERE bonus > ? AND bonus < ?";
$stmt = $conn->prepare($sql);
if (!$stmt) {
// Handle errors
}
$stmt->execute($stmt);
If you successfully execute a prepared statement that returns one or more result
sets, you can begin retrieving rows from the statement resource by calling the
PDOStatement::fetch() or PDOStatement::fetchAll() methods.
Related reference:
v “PDO::prepare - Prepares a statement for execution and returns a statement
object” on page 107
v “PDOStatement::bindParam - Binds a parameter to the specified variable name”
on page 113
v “PDOStatement::execute - Executes a prepared statement” on page 118
Prerequisites:
You must set up the PHP 5.1 or higher environment on your system and enable
the PDO and PDO_ODBC extensions.
Procedure:
Example:
$stmt = $conn->prepare("INSERT INTO animal_pictures(picture) VALUES (?)");
$picture = fopen("/opt/albums/spook/grooming.jpg", "rb");
$stmt->bindParam($stmt, 1, $picture, PDO::PARAM_LOB);
$stmt->execute();
Related reference:
v “PDO::prepare - Prepares a statement for execution and returns a statement
object” on page 107
v “PDOStatement::bindParam - Binds a parameter to the specified variable name”
on page 113
v “PDOStatement::execute - Executes a prepared statement” on page 118
Prerequisites:
v You must set up the PHP environment on your system and enable the PDO and
PDO_ODBC extensions.
v You must have a statement resource returned from PDO::query() or
PDOStatement::execute() with one or more associated result sets.
Restrictions:
If you decide to fetch a column from a row, instead of retrieving all of the columns
in the entire row simultaneously, you can only return a single column from each
row.
Procedure:
To return an array containing a single column from all of the remaining rows in
the result set:
1. Call the PDOStatement::fetchAll() method, passing PDO::FETCH_COLUMN as the
first argument, and the column you want to retrieve as the second argument, to
return an array of the values for the selected column from the result set.
Column numbers start at 0. If you do not specify a column,
PDOStatement::fetchAll(PDO::FETCH_COLUMN) returns the first column in the
row.
Related tasks:
v “Fetching large objects in PHP (PDO)” on page 31
v “Fetching rows from result sets in PHP (PDO)” on page 29
Related reference:
v “PDOStatement::fetchColumn - Returns a single column from the next row of a
result set” on page 124
v “PDO::query - Executes an SQL statement, returning a result set as a
PDOStatement object” on page 108
v “PDOStatement::execute - Executes a prepared statement” on page 118
v “PDOStatement::fetchAll - Returns an array containing all of the result set rows”
on page 122
Prerequisites:
v You must set up the PHP environment on your system and enable the PDO
extension.
v You must have a PDOStatement object returned from PDO::query() or
PDOStatement::execute() with one or more associated result sets.
Procedure:
To return a single row from a result set as an array or object, call the
PDOStatement::fetch() method.
To return all of the rows from the result set as an array of arrays or objects, call the
PDOStatement::fetchAll() method.
By default, PDO returns each row as an array indexed by column name and
0-indexed column position in the row. You can request a different return style by
passing one of the following constants as the first parameter of
PDOStatement::fetch():
PDO::FETCH_ASSOC
Returns an array indexed by column name as returned in your result set.
PDOStatement::fetch() returns FALSE when the last row in the result set has been
retrieved for a forward-only result set.
Example:
Related tasks:
v “Fetching large objects in PHP (PDO)” on page 31
Related reference:
v “PDOStatement::fetch - Fetches the next row from a result set” on page 119
v “PDOStatement::fetchAll - Returns an array containing all of the result set rows”
on page 122
Prerequisites:
You must set up the PHP 5.1 or higher environment on your system and enable
the PDO and PDO_ODBC extensions.
Procedure:
Example:
$stmt = $conn->prepare("SELECT name, picture FROM animal_pictures");
$picture = fopen("/opt/albums/spook/grooming.jpg", "wb");
$stmt->bindColumn($stmt, 1, $nickname, PDO::PARAM_STR, 32);
$stmt->bindColumn($stmt, 2, $picture, PDO::PARAM_LOB);
$stmt->execute();
$stmt->fetch(PDO::FETCH_BOUND);
Related tasks:
Related reference:
v “PDO::prepare - Prepares a statement for execution and returns a statement
object” on page 107
v “PDOStatement::bindParam - Binds a parameter to the specified variable name”
on page 113
v “PDOStatement::execute - Executes a prepared statement” on page 118
v “PDOStatement::fetch - Fetches the next row from a result set” on page 119
Prerequisites:
You must set up the PHP environment on your system and enable the PDO
extension.
Procedure:
To begin a transaction:
1. Call PDO::beginTransaction() to begin a new transaction.
2. Issue one or more SQL statements within the scope of the database transaction
using the connection resource for which transactions have been enabled.
3. Commit or rollback the transaction:
v To commit the transaction, call PDO::commit().
v To rollback the transaction, call PDO::rollBack().
After you commit or rollback the transaction, PDO automatically resets the
database connection to autocommit mode. If you issue SQL statements in a
transaction and the script ends without explicitly committing or rolling back the
transaction, PDO automatically rolls back any work performed in the transaction.
Example:
$conn = new PDO(’odbc:SAMPLE’, ’db2inst1’, ’ibmdb2’, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
// PDO::ERRMODE_EXCEPTION means an SQL error throws an exception
try {
// Issue these SQL statements in a transaction within a try{} block
$conn->beginTransaction();
$conn->commit();
}
catch (Exception $e) {
// If something raised an exception in our transaction block of statements,
// roll back any work performed in the transaction
print ’<p>Unable to complete transaction!</p>’;
$conn->rollBack();
}
Prerequisites:
You must set up the PHP environment on your system and enable the PDO and
PDO_ODBC extensions.
Restrictions:
PDO gives you the option of handling errors as warnings, errors, or exceptions.
However, when you create a new PDO connection object, PDO always throws a
PDOException object if an error occurs. If you do not catch the exception, PHP
prints a backtrace of the error information which might expose your database
connection credentials, including your user name and password.
Procedure:
v To catch a PDOException object and handle the associated error:
1. Wrap the call to the PDO constructor in a try block.
2. Following the try block, include a catch block that catches the PDOException
object.
3. Retrieve the error message associated with the error by invoking the
Exception::getMessage() method on the PDOException object.
v To retrieve the SQLSTATE associated with a PDO or PDOStatement object, invoke
the errorCode() method on the object.
v To retrieve an array of error information associated with a PDO or PDOStatement
object, invoke the errorInfo() method on the object. The array contains a string
representing the SQLSTATE as the first element, an integer representing the SQL
or CLI error code as the second element, and a string containing the full text
error message as the third element.
You must set up the PHP environment on your system and enable the PDO and
PDO_ODBC extensions.
Procedure:
Example:
$sql = ’CALL match_animal(?, ?)’;
$stmt = $conn->prepare($sql);
$stmt->execute();
Related tasks:
v “Calling stored procedures that return multiple result sets in PHP (PDO)” on
page 35
Related reference:
v “PDO::prepare - Prepares a statement for execution and returns a statement
object” on page 107
Calling stored procedures that return multiple result sets in PHP (PDO)
DB2 enables you to create and call stored procedures that return more than one
result set. The PDO_ODBC extension for PHP supports this capability through the
nextRowset() method. You can use this method to fetch rows from different result
sets returned by a single call to the same stored procedure.
Prerequisites:
v You must set up the PHP 5.1 or higher environment on your system and enable
the PDO and PDO_ODBC extensions.
v You must have a PDOStatement object returned from calling a stored procedure
with PDO::query() or PDOStatement::execute().
Procedure:
Example:
$sql = ’CALL multiple_results()’;
$stmt = $conn->query($sql);
do {
$rows = $stmt->fetchAll(PDO::FETCH_NUM);
if ($rows) {
print_r($rows);
}
} while ($stmt->nextRowset());
Related tasks:
v “Calling stored procedures with OUT or INOUT parameters in PHP (PDO)” on
page 33
Related reference:
v “PDOStatement::nextRowset - Advances to the next result set in a statement
handle associated with multiple result sets” on page 127
Description:
Parameters:
connection
A valid database connection resource variable as returned from
db2_connect() or db2_pconnect().
value
One of the following constants:
DB2_AUTOCOMMIT_OFF
Turns AUTOCOMMIT off.
DB2_AUTOCOMMIT_ON
Turns AUTOCOMMIT on.
Return Values:
Examples:
// Turn AUTOCOMMIT on
$rc = db2_autocommit($conn, DB2_AUTOCOMMIT_ON);
if ($rc) {
print "Turning AUTOCOMMIT on succeeded.\n";
}
Related tasks:
v “Managing transactions in PHP (ibm_db2)” on page 17
Related reference:
v “db2_commit - Commits a transaction” on page 39
v “db2_rollback - Rolls back a transaction” on page 46
Description:
This function closes a DB2 client connection created with db2_connect() and
returns the corresponding resources to the database management system.
Parameters:
connection
Specifies an active DB2 client connection.
Return Values:
Examples:
Closing a connection:
Related tasks:
v “Connecting to a DB2 database with PHP (ibm_db2)” on page 7
Related reference:
v “db2_connect - Returns a connection to a database” on page 42
v “db2_pconnect - Returns a persistent connection to a database” on page 45
Description:
Parameters:
connection
A valid database connection resource variable as returned from
db2_connect().
Return Values:
Related tasks:
v “Managing transactions in PHP (ibm_db2)” on page 17
Related reference:
v “db2_rollback - Rolls back a transaction” on page 46
v “db2_autocommit - Returns or sets the AUTOCOMMIT state for a database
connection” on page 37
Description:
If, however, the connection was successful but becomes invalid over time, you can
pass the connection parameter to retrieve the SQLSTATE value for a specific
connection.
To learn what the SQLSTATE value means, you can issue the following command
at a DB2 Command Line Processor prompt:
db2 ’? sqlstate-value'
You can also call db2_conn_errormsg() to retrieve an explicit error message and the
associated SQLCODE value.
Parameters:
connection
A connection resource associated with a connection that initially succeeded,
but which over time became invalid.
Return Values:
Returns the SQLSTATE value resulting from a failed connection attempt. Returns
an empty string if there is no error associated with the last connection attempt.
Examples:
<?php
$conn = db2_connect(’badname’, ’baduser’, ’badpassword’);
if (!$conn) {
print "SQLSTATE value: " . db2_conn_error();
}
?>
Related tasks:
v “Handling errors and warning messages (ibm_db2)” on page 18
Related reference:
v “db2_conn_errormsg - Returns the last connection error message and SQLCODE
value” on page 41
v “db2_stmt_error - Returns a string containing the SQLSTATE returned by an
SQL statement” on page 57
v “db2_stmt_errormsg - Returns a string containing the last SQL statement error
message” on page 57
Description:
If, however, the connection was successful but becomes invalid over time, you can
pass the connection parameter to retrieve the associated error message and
SQLCODE value for a specific connection.
Parameters:
connection
A connection resource associated with a connection that initially succeeded,
but which over time became invalid.
Return Values:
Returns a string containing the error message and SQLCODE value resulting from
a failed connection attempt. If there is no error associated with the last connection
attempt, db2_conn_errormsg() returns an empty string.
Examples:
Related tasks:
v “Handling errors and warning messages (ibm_db2)” on page 18
Related reference:
v “db2_conn_error - Returns a string containing the SQLSTATE returned by the
last connection attempt” on page 40
v “db2_stmt_error - Returns a string containing the SQLSTATE returned by an
SQL statement” on page 57
v “db2_stmt_errormsg - Returns a string containing the last SQL statement error
message” on page 57
Description:
Parameters:
database
For a cataloged connection to a database, database represents the database
alias in the DB2 client catalog.
For an uncataloged connection to a database, database represents a complete
connection string in the following format:
DRIVER={IBM DB2 ODBC DRIVER};DATABASE=database;HOSTNAME=hostname;
PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password
port
The TCP/IP port on which the database is listening for requests.
username
The username with which you are connecting to the database.
password
The password with which you are connecting to the database.
username
The user name with which you are connecting to the database.
For uncataloged connections, you must pass a NULL value or empty
string.
password
The password with which you are connecting to the database.
For uncataloged connections, you must pass a NULL value or empty
string.
options
An associative array of connection options that affect the behavior of the
connection, where valid array keys include:
autocommit
Passing the DB2_AUTOCOMMIT_ON value turns autocommit on
for this connection handle.
Passing the DB2_AUTOCOMMIT_OFF value turns autocommit
off for this connection handle.
Return Values:
Examples:
Cataloged connections require you to have previously cataloged the target database
through the DB2 Command Line Processor or DB2 Configuration Assistant.
<?php
$database = ’SAMPLE’;
$user = ’db2inst1’;
$password = ’ibmdb2’;
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>
if ($conn) {
echo "Connection succeeded.\n";
if (db2_autocommit($conn)) {
echo "Autocommit is on.\n";
}
else {
echo "Autocommit is off.\n";
}
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>
Related tasks:
v “Connecting to a DB2 database with PHP (ibm_db2)” on page 7
44 Developing Perl and PHP Applications
db2_connect - Returns a connection to a database
Related reference:
v “db2_close - Closes a database connection” on page 38
v “db2_pconnect - Returns a persistent connection to a database” on page 45
Description:
Note that you are strongly urged to only use persistent connections on connections
with autocommit turned on. If you attempt to combine transactions with persistent
connections, issuing db2_commit() or db2_rollback() against a persistent
connection will affect every persistent connection that is currently using the same
underlying DB2 client connection. You may also rapidly experience locking
escalation if you do not use autocommit for your persistent connections.
Parameters:
database
The database alias in the DB2 client catalog.
username
The username with which you are connecting to the database.
password
The password with which you are connecting to the database.
options
An associative array of connection options that affect the behavior of the
connection, where valid array keys include:
autocommit
Passing the DB2_AUTOCOMMIT_ON value turns autocommit on
for this connection handle.
Passing the DB2_AUTOCOMMIT_OFF value turns autocommit
off for this connection handle.
Return Values:
Examples:
A db2_pconnect() example:
In the following example, the first call to db2_pconnect() returns a new persistent
connection resource. The second call to db2_pconnect() returns a persistent
connection resource that simply reuses the first persistent connection resource.
<?php
$database = ’SAMPLE’;
$user = ’db2inst1’;
$password = ’ibmdb2’;
if ($pconn) {
echo "Persistent connection succeeded.";
}
else {
echo "Persistent connection failed.";
}
Related tasks:
v “Connecting to a DB2 database with PHP (ibm_db2)” on page 7
Related reference:
v “db2_connect - Returns a connection to a database” on page 42
Description:
Parameters:
connection
A valid database connection resource variable as returned from
db2_connect() or db2_pconnect().
Return Values:
Examples:
In the following example, we count the number of rows in a table, turn off
AUTOCOMMIT mode on a database connection, delete all of the rows in the table
and return the count of 0 to prove that the rows have been removed. We then issue
db2_rollback() and return the updated count of rows in the table to show that the
number is the same as before we issued the DELETE statement. The return to the
original state of the table demonstrates that the roll back of the transaction
succeeded.
<?php
$conn = db2_connect($database, $user, $password);
if ($conn) {
$stmt = db2_exec($conn, "SELECT count(*) FROM animals");
$res = db2_fetch_array( $stmt );
echo $res[0] . "\n";
Related tasks:
v “Managing transactions in PHP (ibm_db2)” on page 17
Related reference:
v “db2_commit - Commits a transaction” on page 39
Statement functions
Description:
Parameters:
stmt
A prepared statement returned from db2_prepare().
parameter-number
Specifies the 1-indexed position of the parameter in the prepared
statement.
variable-name
A string specifying the name of the PHP variable to bind to the parameter
specified by parameter-number.
parameter-type
A constant specifying whether the PHP variable should be bound to the
SQL parameter as an input parameter (DB2_PARAM_IN), an output
parameter (DB2_PARAM_OUT), or as a parameter that accepts input and
returns output (DB2_PARAM_INOUT).
data-type
A constant specifying the SQL data type that the PHP variable should be
bound as: one of DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or
DB2_LONG .
precision
Specifies the precision with which the variable should be bound to the
database.
scale
Specifies the scale with which the variable should be bound to the
database.
Return Values:
Examples:
The SQL statement in the following example uses two input parameters in the
WHERE clause. We call db2_bind_param() to bind two PHP variables to the
corresponding SQL parameters. Notice that the PHP variables do not have to be
declared or assigned before the call to db2_bind_param(); in the example,
$lower_limit is assigned a value before the call to db2_bind_param(), but
$upper_limit is assigned a value after the call to db2_bind_param(). The variables
must be bound and, for parameters that accept input, must have any value
assigned, before calling db2_execute().
<?php
if (db2_execute($stmt)) {
while ($row = db2_fetch_array($stmt)) {
print "{$row[0]}, {$row[1]}, {$row[2]}\n";
}
}
?>
$name = "Peaches";
$second_name = "Rickety Ride";
db2_bind_param($stmt, 1, "name", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT);
db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT);
if (db2_execute($stmt)) {
print "Values of bound parameters _after_ CALL:\n";
print " 1: {$name} 2: {$second_name} 3: {$weight}\n\n";
print "Results:\n";
while ($row = db2_fetch_array($stmt)) {
print " {$row[0]}, {$row[1]}, {$row[2]}\n";
}
}
?>
Results:
Peaches, dog, 12.3
Pook, cat, 3.2
Rickety Ride, goat, 9.7
Related tasks:
v “Calling stored procedures with OUT or INOUT parameters in PHP (ibm_db2)”
on page 20
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Description:
If you plan to interpolate PHP variables into the SQL statement, understand that
this is one of the more common security exposures. Consider calling db2_prepare()
to prepare an SQL statement with parameter markers for input values. Then you
can call db2_execute() to pass in the input values and avoid SQL injection attacks.
If you plan to repeatedly issue the same SQL statement with different parameters,
consider calling db2_prepare() and db2_execute() to enable the database
management system to reuse its access plan and increase the efficiency of your
database access.
Parameters:
connection
A valid database connection resource variable as returned from
db2_connect() or db2_pconnect().
statement
An SQL statement. The statement cannot contain any parameter markers.
options
An associative array containing statement options. You can use this
parameter to request a scrollable cursor on database management system
that support this functionality.
cursor
Passing the DB2_FORWARD_ONLY value requests a forward-only
cursor for this SQL statement. This is the default type of cursor,
and it is supported by all database management system. It is also
much faster than a scrollable cursor.
Passing the DB2_SCROLLABLE value requests a scrollable cursor
for this SQL statement. This type of cursor enables you to fetch
rows non-sequentially from the database management system.
However, it is only supported by DB2 management system, and is
much slower than forward-only cursors.
Return Values:
Examples:
The following example uses db2_exec() to issue a set of DDL statements in the
process of creating a table.
<?php
$conn = db2_connect($database, $user, $password);
The following example demonstrates how to request a scrollable cursor for an SQL
statement issued by db2_exec().
<?php
$conn = db2_connect($database, $user, $password);
$sql = "SELECT name FROM animals
WHERE weight < 10.0
ORDER BY name";
if ($conn) {
require_once(’prepare.inc’);
$stmt = db2_exec($conn, $sql, array(’cursor’ => DB2_SCROLLABLE));
while ($row = db2_fetch_array($stmt)) {
print "$row[0]\n";
}
}
?>
Related tasks:
v “Executing a single SQL statement in PHP (ibm_db2)” on page 11
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Description:
If the SQL statement returns a result set, for example, a SELECT statement or a
CALL to a stored procedure that returns one or more result sets, you can retrieve a
row as an array from the stmt resource using db2_fetch_assoc(),
db2_fetch_both(), or db2_fetch_array(). Alternatively, you can use
db2_fetch_row() to move the result set pointer to the next row and fetch a column
at a time from that row with db2_result().
Parameters:
stmt
A prepared statement returned from db2_prepare().
parameters
An array of input parameters matching any parameter markers contained
in the prepared statement.
Return Values:
Examples:
The following example prepares an INSERT statement that accepts four parameter
markers, then iterates over an array of arrays containing the input values to be
passed to db2_execute().
<?php
$pet = array(0, ’cat’, ’Pook’, 3.2);
The following example prepares a CALL statement that accepts one parameter
marker representing an OUT parameter, binds the PHP variable $my_pets to the
parameter using db2_bind_param, then issues db2_execute to execute the CALL
statement. After the CALL to the stored procedure has been made, the value of
$num_pets changes to reflect the value returned by the stored procedure for that
OUT parameter.
<?php
$num_pets = 0;
$res = db2_prepare($conn, "CALL count_my_pets(?)");
$rc = db2_bind_param($res, 1, "num_pets", DB2_PARAM_OUT);
$rc = db2_execute($res);
print "I have $num_pets pets!";
?>
Related tasks:
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_exec - Executes an SQL statement directly” on page 50
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Description:
Frees the system and database resources that are associated with a result set. These
resources are freed implicitly when a script finishes, but you can call
db2_free_result() to explicitly free the result set resources before the end of the
script.
Parameters:
stmt
A valid statement resource.
Return Values:
Related reference:
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_free_stmt - Frees resources associated with the indicated statement
resource” on page 54
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Description:
Frees the system and database resources that are associated with a statement
resource. These resources are freed implicitly when a script finishes, but you can
call db2_free_stmt() to explicitly free the statement resources before the end of the
script.
Parameters:
stmt
A valid statement resource.
Return Values:
Related reference:
v “db2_execute - Executes a prepared SQL statement” on page 52
v “db2_free_result - Frees resources associated with a result set” on page 54
v “db2_prepare - Prepares an SQL statement to be executed” on page 55
Description:
There are three main advantages to using prepared statements in your application:
1.
Performance: when you prepare a statement, the database management system
creates an optimized access plan for retrieving data with that statement.
Subsequently issuing the prepared statement with db2_execute() enables the
statements to reuse that access plan and avoids the overhead of dynamically
creating a new access plan for every statement you issue.
2.
Security: when you prepare a statement, you can include parameter markers for
input values. When you execute a prepared statement with input values for
placeholders, the database management system checks each input value to
ensure that the type matches the column definition or parameter definition.
3.
Advanced functionality: Parameter markers not only enable you to pass input
values to prepared SQL statements, they also enable you to retrieve OUT and
INOUT parameters from stored procedures using db2_bind_param().
Parameters:
connection
Return Values:
Returns a statement resource if the SQL statement was successfully parsed and
prepared by the database management system. Returns FALSE if the database
management system returned an error. You can determine which error was
returned by calling db2_stmt_error() or db2_stmt_errormsg().
Examples:
The following example prepares an INSERT statement that accepts four parameter
markers, then iterates over an array of arrays containing the input values to be
passed to db2_execute().
<?php
$animals = array(
array(0, ’cat’, ’Pook’, 3.2),
array(1, ’dog’, ’Peaches’, 12.3),
array(2, ’horse’, ’Smarty’, 350.0),
);
Related tasks:
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_bind_param - Binds a PHP variable to an SQL statement parameter” on
page 48
v “db2_execute - Executes a prepared SQL statement” on page 52
Description:
To learn what the SQLSTATE value means, you can issue the following command
at a DB2 Command Line Processor prompt:
db2 ’? sqlstate-value’
. You can also call db2_stmt_errormsg() to retrieve an explicit error message and
the associated SQLCODE value.
Parameters:
stmt
A valid statement resource.
Return Values:
Related tasks:
v “Handling errors and warning messages (ibm_db2)” on page 18
Related reference:
v “db2_stmt_errormsg - Returns a string containing the last SQL statement error
message” on page 57
v “db2_conn_error - Returns a string containing the SQLSTATE returned by the
last connection attempt” on page 40
v “db2_conn_errormsg - Returns the last connection error message and SQLCODE
value” on page 41
Description:
Parameters:
stmt
A valid statement resource.
Return Values:
Returns a string containing the error message and SQLCODE value for the last
error that occurred issuing an SQL statement.
Related tasks:
v “Handling errors and warning messages (ibm_db2)” on page 18
Related reference:
v “db2_conn_error - Returns a string containing the SQLSTATE returned by the
last connection attempt” on page 40
v “db2_conn_errormsg - Returns the last connection error message and SQLCODE
value” on page 41
v “db2_stmt_error - Returns a string containing the SQLSTATE returned by an
SQL statement” on page 57
Fetch functions
Description:
Parameters:
stmt
A valid stmt resource containing a result set.
row_number
Requests a specific 1-indexed row from the result set. Passing this
parameter results in a PHP warning if the result set uses a forward-only
cursor.
Return Values:
Returns a 0-indexed array with column values indexed by the column position
representing the next or requested row in the result set. Returns FALSE if there are
no rows left in the result set, or if the row requested by row_number does not
exist in the result set.
Examples:
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
If your result set uses a scrollable cursor, you can call db2_fetch_array() with a
specific row number. The following example retrieves every other row in the result
set, starting with the second row.
<?php
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$result = db2_exec($stmt, $sql, array(’cursor’ => DB2_SCROLLABLE));
$i=2;
while ($row = db2_fetch_array($result, $i)) {
printf ("%-5d %-16s %-32s %10s\n",
$row[0], $row[1], $row[2], $row[3]);
$i = $i + 2;
}
?>
Related tasks:
v “Fetching large objects in PHP (ibm_db2)” on page 17
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Related reference:
v “db2_fetch_assoc - Returns an array, indexed by column name, representing a
row in a result set” on page 60
Description:
Parameters:
stmt
A valid stmt resource containing a result set.
row_number
Requests a specific 1-indexed row from the result set. Passing this
parameter results in a PHP warning if the result set uses a forward-only
cursor.
Return Values:
Returns an associative array with column values indexed by the column name
representing the next or requested row in the result set. Returns FALSE if there are
no rows left in the result set, or if the row requested by row_number does not
exist in the result set.
Examples:
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
If your result set uses a scrollable cursor, you can call db2_fetch_assoc() with a
specific row number. The following example retrieves every other row in the result
set, starting with the second row.
<?php
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$result = db2_exec($stmt, $sql, array(’cursor’ => DB2_SCROLLABLE));
$i=2;
while ($row = db2_fetch_assoc($result, $i)) {
printf ("%-5d %-16s %-32s %10s\n",
$row[’ID’], $row[’NAME’], $row[’BREED’], $row[’WEIGHT’]);
$i = $i + 2;
}
?>
Related tasks:
v “Fetching large objects in PHP (ibm_db2)” on page 17
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Related reference:
v “db2_fetch_array - Returns an array, indexed by column position, representing a
row in a result set” on page 58
v “db2_fetch_both - Returns an array, indexed by both column name and position,
representing a row in a result set” on page 61
v “db2_fetch_object - Returns an object with properties representing columns in
the fetched row” on page 63
Description:
Returns an array, indexed by both column name and position, representing a row
in a result set. Note that the row returned by db2_fetch_both() requires more
memory than the single-indexed arrays returned by db2_fetch_assoc() or
db2_fetch_array().
Parameters:
stmt
A valid stmt resource containing a result set.
row_number
Requests a specific 1-indexed row from the result set. Passing this
parameter results in a PHP warning if the result set uses a forward-only
cursor.
Return Values:
Returns an associative array with column values indexed by both the column name
and 0-indexed column number. The array represents the next or requested row in
the result set. Returns FALSE if there are no rows left in the result set, or if the row
requested by row_number does not exist in the result set.
Examples:
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$stmt = db2_prepare($conn, $sql);
$result = db2_execute($stmt);
If your result set uses a scrollable cursor, you can call db2_fetch_both() with a
specific row number. The following example retrieves every other row in the result
set, starting with the second row.
<?php
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$result = db2_exec($stmt, $sql, array(’cursor’ => DB2_SCROLLABLE));
$i=2;
while ($row = db2_fetch_both($result, $i)) {
printf ("%-5d %-16s %-32s %10s\n",
$row[0], $row[’NAME’], $row[2], $row[’WEIGHT’]);
$i = $i + 2;
}
?>
Related tasks:
v “Fetching large objects in PHP (ibm_db2)” on page 17
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Related reference:
Description:
Returns an object in which each property represents a column returned in the row
fetched from a result set.
Parameters:
stmt
A valid stmt resource containing a result set.
row_number
Requests a specific 1-indexed row from the result set. Passing this
parameter results in a PHP warning if the result set uses a forward-only
cursor.
Return Values:
Returns an object representing a single row in the result set. The properties of the
object map to the names of the columns in the result set.
The IBM DB2, Cloudscape, and Apache Derby database management systems
typically fold column names to upper-case, so the object properties will reflect that
case.
If your SELECT statement calls a scalar function to modify the value of a column,
the database management systems return the column number as the name of the
column in the result set. If you prefer a more descriptive column name and object
property, you can use the AS clause to assign a name to the column in the result
set.
Examples:
A db2_fetch_object() example:
The following example issues a SELECT statement with a scalar function, RTRIM(),
that removes whitespace from the end of the column. Rather than creating an
object with the properties ″BREED″ and ″2″, we use the AS clause in the SELECT
statement to assign the name ″name″ to the modified column. The database
if ($conn) {
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(0));
Related tasks:
v “Fetching large objects in PHP (ibm_db2)” on page 17
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Related reference:
v “db2_fetch_array - Returns an array, indexed by column position, representing a
row in a result set” on page 58
v “db2_fetch_assoc - Returns an array, indexed by column name, representing a
row in a result set” on page 60
v “db2_fetch_both - Returns an array, indexed by both column name and position,
representing a row in a result set” on page 61
Description:
To retrieve individual fields from the result set, call the db2_result() function.
Rather than calling db2_fetch_row() and db2_result(), most applications will call
one of db2_fetch_assoc(), db2_fetch_both(), or db2_fetch_array() to advance the
result set pointer and return a complete row as an array.
Parameters:
stmt
Return Values:
Returns TRUE if the requested row exists in the result set. Returns FALSE if the
requested row does not exist in the result set.
Examples:
The following example demonstrates how to iterate through a result set with
db2_fetch_row() and retrieve columns from the result set with db2_result().
<?php
$sql = ’SELECT name, breed FROM animals WHERE weight < ?’;
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(10));
while (db2_fetch_row($stmt)) {
$name = db2_result($stmt, 0);
$breed = db2_result($stmt, 1);
print "$name $breed";
}
?>
Related tasks:
v “Fetching columns from result sets in PHP (ibm_db2)” on page 15
Related reference:
v “db2_result - Returns a single column from a row in the result set” on page 67
Description:
A stored procedure can return zero or more result sets. While you handle the first
result set in exactly the same way you would handle the results returned by a
simple SELECT statement, to fetch the second and subsequent result sets from a
stored procedure you must call the db2_next_result() function and return the
result to a uniquely named PHP variable.
Parameters:
stmt
A prepared statement returned from db2_exec() or db2_execute().
Return Values:
Returns a new statement resource containing the next result set if the stored
procedure returned another result set. Returns FALSE if the stored procedure did
not return another result set.
Examples:
In the following example, we call a stored procedure that returns three result sets.
The first result set is fetched directly from the same statement resource on which
we invoked the CALL statement, while the second and third result sets are fetched
from statement resources returned from our calls to the db2_next_result()
function.
<?php
$conn = db2_connect($database, $user, $password);
if ($conn) {
$stmt = db2_exec($conn, ’CALL multiResults()’);
db2_close($conn);
}
?>
Related tasks:
v “Calling stored procedures that return multiple result sets in PHP (ibm_db2)” on
page 21
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Description:
Use db2_result() to return the value of a specified column in the current row of a
result set. You must call db2_fetch_row() before calling db2_result() to set the
location of the result set pointer.
Parameters:
stmt
A valid stmt resource.
column
Either an integer mapping to the 0-indexed field in the result set, or a
string matching the name of the column.
Return Values:
Returns the value of the requested field if the field exists in the result set. Returns
NULL if the field does not exist, and issues a warning.
Examples:
A db2_result() example:
The following example demonstrates how to iterate through a result set with
db2_fetch_row() and retrieve columns from the result set with db2_result().
<?php
$sql = ’SELECT name, breed FROM animals WHERE weight < ?’;
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, array(10));
while (db2_fetch_row($stmt)) {
$name = db2_result($stmt, 0);
$breed = db2_result($stmt, ’BREED’);
print "$name $breed";
}
?>
Related tasks:
v “Fetching columns from result sets in PHP (ibm_db2)” on page 15
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Related reference:
v “db2_fetch_row - Sets the result set pointer to the next row or requested row”
on page 64
Metadata functions
Description:
This function returns an object with read-only properties that return information
about the DB2 database client. The following table lists the DB2 client properties:
Table 1. DB2 client properties
Property name Return type Description
APPL_CODEPAGE int The application code page.
Parameters:
connection
Specifies an active DB2 client connection.
Return Values:
Examples:
A db2_client_info example:
To retrieve information about the client, you must pass a valid database connection
resource to db2_client_info().
<?php
$conn = db2_connect( ’SAMPLE’, ’db2inst1’, ’ibmdb2’ );
$client = db2_client_info( $conn );
if ($client) {
echo "DRIVER_NAME: "; var_dump( $client->DRIVER_NAME );
echo "DRIVER_VER: "; var_dump( $client->DRIVER_VER );
echo "DATA_SOURCE_NAME: "; var_dump( $client->DATA_SOURCE_NAME );
echo "DRIVER_ODBC_VER: "; var_dump( $client->DRIVER_ODBC_VER );
echo "ODBC_VER: "; var_dump( $client->ODBC_VER );
echo "ODBC_SQL_CONFORMANCE: "; var_dump( $client->ODBC_SQL_CONFORMANCE );
echo "APPL_CODEPAGE: "; var_dump( $client->APPL_CODEPAGE );
echo "CONN_CODEPAGE: "; var_dump( $client->CONN_CODEPAGE );
}
else {
echo "Error retrieving client information.
Perhaps your database connection was invalid.";
}
db2_close($conn);
?>
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_server_info - Returns an object with properties that describe the DB2
database management system” on page 79
Description:
Returns a result set listing the columns and associated privileges for a table.
Parameters:
connection
Return Values:
Returns a statement resource with a result set containing rows describing the
column privileges for columns matching the specified parameters. The rows are
composed of the following columns:
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_columns - Returns a result set listing the columns and associated metadata
for a table” on page 71
Description:
Returns a result set listing the columns and associated metadata for a table.
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the tables. To match all schemas, pass ’%’.
table-name
The name of the table or view. To match all tables in the database, pass
NULL or an empty string.
column-name
The name of the column. To match all columns in the table, pass NULL or
an empty string.
Return Values:
Returns a statement resource with a result set containing rows describing the
columns matching the specified parameters. The rows are composed of the
following columns:
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_column_privileges - Returns a result set listing the columns and associated
privileges for a table” on page 70
Description:
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the tables. If schema is NULL,
db2_foreign_keys() matches the schema for the current connection.
table-name
The name of the table.
Return Values:
Returns a statement resource with a result set containing rows describing the
foreign keys for the specified table. The result set is composed of the following
columns:
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_primary_keys - Returns a result set listing primary keys for a table” on
page 74
Description:
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the tables. If schema is NULL,
db2_primary_keys() matches the schema for the current connection.
table-name
The name of the table.
Return Values:
Returns a statement resource with a result set containing rows describing the
primary keys for the specified table. The result set is composed of the following
columns:
Table 2. db2_primary_keys() result set columns
Column name Description
TABLE_CAT Name of the catalog for the table containing
the primary key. The value is NULL if this
table does not have catalogs.
TABLE_SCHEM Name of the schema for the table containing
the primary key.
TABLE_NAME Name of the table containing the primary
key.
COLUMN_NAME Name of the column containing the primary
key.
KEY_SEQ 1-indexed position of the column in the key.
PK_NAME The name of the primary key.
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_foreign_keys - Returns a result set listing the foreign keys for a table” on
page 73
Description:
Returns a result set listing the parameters for one or more stored procedures.
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the procedures. This parameter accepts a
search pattern containing _ and % as wildcards.
procedure
The name of the procedure. This parameter accepts a search pattern
containing _ and % as wildcards.
parameter
The name of the parameter. This parameter accepts a search pattern
containing _ and % as wildcards. If this parameter is NULL, all parameters
for the specified stored procedures are returned.
Return Values:
Returns a statement resource with a result set containing rows describing the
parameters for the stored procedures matching the specified parameters. The rows
are composed of the following columns:
Table 3. db2_procedure_columns() result set columns
Column name Description
PROCEDURE_CAT The catalog that contains the procedure. The
value is NULL if this table does not have
catalogs.
PROCEDURE_SCHEM Name of the schema that contains the stored
procedure.
PROCEDURE_NAME Name of the procedure.
COLUMN_NAME Name of the parameter.
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_procedures - Returns a result set listing the stored procedures registered in
a database” on page 78
Description:
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the procedures. This parameter accepts a
search pattern containing _ and % as wildcards.
procedure
The name of the procedure. This parameter accepts a search pattern
containing _ and % as wildcards.
Return Values:
Returns a statement resource with a result set containing rows describing the
stored procedures matching the specified parameters. The rows are composed of
the following columns:
Table 4. db2_procedures() result set columns
Column name Description
PROCEDURE_CAT The catalog that contains the procedure. The
value is NULL if this table does not have
catalogs.
PROCEDURE_SCHEM Name of the schema that contains the stored
procedure.
PROCEDURE_NAME Name of the procedure.
NUM_INPUT_PARAMS Number of input (IN) parameters for the
stored procedure.
NUM_OUTPUT_PARAMS Number of output (OUT) parameters for the
stored procedure.
NUM_RESULT_SETS Number of result sets returned by the stored
procedure.
REMARKS Any comments about the stored procedure.
Description:
This function returns an object with read-only properties that return information
about the IBM DB2, Cloudscape, or Apache Derby database management system.
The following table lists the database management system properties:
Table 5. Database management system properties
Property name Return type Description
DBMS_NAME string The name of the database
management system to which
you are connected. For DB2
management systems this is a
combination of DB2 followed by
the operating system on which
the database management
system is running.
DBMS_VER string The version of the database
management system, in the form
of a string ″MM.mm.uuuu″
where MM is the major version,
mm is the minor version, and
uuuu is the update. For example,
″08.02.0001″ represents major
version 8, minor version 2,
update 1.
DB_CODEPAGE int The code page of the database to
which you are connected.
DB_NAME string The name of the database to
which you are connected.
Parameters:
connection
Specifies an active DB2 client connection.
Return Values:
Examples:
A db2_server_info() example:
To retrieve information about the database management system, you must pass a
valid database connection resource to db2_server_info().
<?php
if ($server) {
echo "DBMS_NAME: "; var_dump( $server->DBMS_NAME );
echo "DBMS_VER: "; var_dump( $server->DBMS_VER );
echo "DB_CODEPAGE: "; var_dump( $server->DB_CODEPAGE );
echo "DB_NAME: "; var_dump( $server->DB_NAME );
echo "INST_NAME: "; var_dump( $server->INST_NAME );
echo "SPECIAL_CHARS: "; var_dump( $server->SPECIAL_CHARS );
echo "KEYWORDS: "; var_dump( sizeof($server->KEYWORDS) );
echo "DFT_ISOLATION: "; var_dump( $server->DFT_ISOLATION );
echo "ISOLATION_OPTION: ";
$il = ’’;
foreach( $server->ISOLATION_OPTION as $opt )
{
$il .= $opt." ";
}
var_dump( $il );
echo "SQL_CONFORMANCE: "; var_dump( $server->SQL_CONFORMANCE );
echo "PROCEDURES: "; var_dump( $server->PROCEDURES );
echo "IDENTIFIER_QUOTE_CHAR: "; var_dump( $server->IDENTIFIER_QUOTE_CHAR );
echo "LIKE_ESCAPE_CLAUSE: "; var_dump( $server->LIKE_ESCAPE_CLAUSE );
echo "MAX_COL_NAME_LEN: "; var_dump( $server->MAX_COL_NAME_LEN );
echo "MAX_ROW_SIZE: "; var_dump( $server->MAX_ROW_SIZE );
echo "MAX_IDENTIFIER_LEN: "; var_dump( $server->MAX_IDENTIFIER_LEN );
echo "MAX_INDEX_SIZE: "; var_dump( $server->MAX_INDEX_SIZE );
echo "MAX_PROC_NAME_LEN: "; var_dump( $server->MAX_PROC_NAME_LEN );
echo "MAX_SCHEMA_NAME_LEN: "; var_dump( $server->MAX_SCHEMA_NAME_LEN );
echo "MAX_STATEMENT_LEN: "; var_dump( $server->MAX_STATEMENT_LEN );
echo "MAX_TABLE_NAME_LEN: "; var_dump( $server->MAX_TABLE_NAME_LEN );
echo "NON_NULLABLE_COLUMNS: "; var_dump( $server->NON_NULLABLE_COLUMNS );
db2_close($conn);
}
?>
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_client_info - Returns an object with properties that describe the DB2
database client” on page 68
Description:
Returns a result set listing the unique row identifier columns for a table.
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the tables.
table_name
The name of the table.
scope
Integer value representing the minimum duration for which the unique
row identifier is valid. This can be one of the values listed in Table 6.
Table 6. Minimum duration of validity for unique row identifiers
Integer value SQL constant Description
0 SQL_SCOPE_CURROW Row identifier is valid only
while the cursor is positioned on
the row.
1 SQL_SCOPE_TRANSACTION Row identifier is valid for the
duration of the transaction.
2 SQL_SCOPE_SESSION Row identifier is valid for the
duration of the connection.
Return Values:
Returns a statement resource with a result set containing rows with unique row
identifier information for a table. The rows are composed of the following
columns:
Table 7. db2_special_columns() result set columns
Column name Description
SCOPE
See Table 6 for the definition of the values
specifying the minimum duration of validity
for unique row identifiers.
COLUMN_NAME Name of the unique column.
DATA_TYPE SQL data type for the column.
TYPE_NAME Character string representation of the SQL
data type for the column.
COLUMN_SIZE An integer value representing the size of the
column.
BUFFER_LENGTH Maximum number of bytes necessary to
store data from this column.
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_statistics - Returns a result set listing the index and statistics for a table”
on page 85
Description:
Returns a result set listing the index and statistics for a table.
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema that contains the targeted table. If this parameter is NULL, the
statistics and indexes are returned for the schema of the current user.
table_name
The name of the table.
unique
An integer value representing the type of index information to return.
0
Return only the information for unique indexes on the table.
1
Return the information for all indexes on the table.
Return Values:
Returns a statement resource with a result set containing rows describing the
statistics and indexes for the base tables matching the specified parameters. The
rows are composed of the following columns:
Table 8. db2_statistics() result set columns
Column name Description
TABLE_CAT The catalog that contains the table. The
value is NULL if this table does not have
catalogs.
TABLE_SCHEM Name of the schema that contains the table.
TABLE_NAME Name of the table.
NON_UNIQUE
An integer value representing whether the
index prohibits unique values, or whether
the row represents statistics on the table
itself:
Return value
Parameter type
0 (SQL_FALSE)
The index allows duplicate values.
1 (SQL_TRUE)
The index values must be unique.
NULL This row provides statistics
information for the table itself.
INDEX_QUALIFIER A string value representing the qualifier that
would have to be prepended to
INDEX_NAME to fully qualify the index.
INDEX_NAME A string representing the name of the index.
TYPE
An integer value representing the type of
information contained in this row of the
result set:
Return value
Parameter type
0 (SQL_TABLE_STAT)
The row contains statistics about
the table itself.
1 (SQL_INDEX_CLUSTERED)
The row contains information about
a clustered index.
2 (SQL_INDEX_HASH)
The row contains information about
a hashed index.
3 (SQL_INDEX_OTHER)
The row contains information about
a type of index that is neither
clustered nor hashed.
ORDINAL_POSITION The 1-indexed position of the column in the
index. NULL if the row contains statistics
information about the table itself.
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_special_columns - Returns a result set listing the unique row identifier
columns for a table” on page 83
Description:
Returns a result set listing the tables and associated privileges in a database.
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the tables. This parameter accepts a search
pattern containing _ and % as wildcards.
table_name
The name of the table. This parameter accepts a search pattern containing _
and % as wildcards.
Return Values:
Returns a statement resource with a result set containing rows describing the
privileges for the tables that match the specified parameters. The rows are
composed of the following columns:
Table 9. db2_privileges() result set columns
Column name Description
TABLE_CAT The catalog that contains the table. The
value is NULL if this table does not have
catalogs.
TABLE_SCHEM Name of the schema that contains the table.
TABLE_NAME Name of the table.
GRANTOR Authorization ID of the user who granted
the privilege.
GRANTEE Authorization ID of the user to whom the
privilege was granted.
PRIVILEGE The privilege that has been granted. This
can be one of ALTER, CONTROL, DELETE,
INDEX, INSERT, REFERENCES, SELECT, or
UPDATE.
IS_GRANTABLE A string value of ″YES″ or ″NO″ indicating
whether the grantee can grant the privilege
to other users.
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_special_columns - Returns a result set listing the unique row identifier
columns for a table” on page 83
v “db2_statistics - Returns a result set listing the index and statistics for a table”
on page 85
v “db2_tables - Returns a result set listing the tables and associated metadata in a
database” on page 88
Description:
Returns a result set listing the tables and associated metadata in a database.
Parameters:
connection
A valid connection to an IBM DB2, Cloudscape, or Apache Derby database.
qualifier
A qualifier for DB2 for z/OS. For other databases, pass NULL or an empty
string.
schema
The schema which contains the tables. This parameter accepts a search
pattern containing _ and % as wildcards.
table-name
The name of the table. This parameter accepts a search pattern containing _
and % as wildcards.
table-type
A list of comma-delimited table type identifiers. To match all table types,
pass NULL or an empty string. Valid table type identifiers include: ALIAS,
HIERARCHY TABLE, INOPERATIVE VIEW, NICKNAME,
MATERIALIZED QUERY TABLE, SYSTEM TABLE, TABLE, TYPED TABLE,
TYPED VIEW, and VIEW.
Return Values:
Returns a statement resource with a result set containing rows describing the tables
that match the specified parameters. The rows are composed of the following
columns:
Table 10. db2_tables() result set columns
Column name Description
TABLE_CAT The catalog that contains the table. The
value is NULL if this table does not have
catalogs.
TABLE_SCHEM Name of the schema that contains the table.
TABLE_NAME Name of the table.
TABLE_TYPE Table type identifier for the table.
REMARKS Description of the table.
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_special_columns - Returns a result set listing the unique row identifier
columns for a table” on page 83
v “db2_statistics - Returns a result set listing the index and statistics for a table”
on page 85
v “db2_table_privileges - Returns a result set listing the tables and associated
privileges in a database” on page 87
Description:
Returns the cursor type used by a statement resource. Use this to determine if you
are working with a forward-only cursor or scrollable cursor.
Parameters:
stmt
A valid statement resource.
Return Values:
Related tasks:
v “Fetching rows from result sets in PHP (ibm_db2)” on page 16
Description:
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns an integer value with the maximum number of bytes required to display
the specified column. If the column does not exist in the result set,
db2_field_display_size() returns FALSE.
Related reference:
v “db2_field_num - Returns the position of the named column in a result set” on
page 92
v “db2_field_precision - Returns the precision of the indicated column in a result
set” on page 92
v “db2_field_scale - Returns the scale of the indicated column in a result set” on
page 93
v “db2_field_type - Returns the data type of the indicated column in a result set”
on page 94
v “db2_field_name - Returns the name of the column in the result set” on page 91
v “db2_field_width - Returns the width of the current value of the indicated
column in a result set” on page 94
Description:
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns a string containing the name of the specified column. If the specified
column does not exist in the result set, db2_field_name() returns FALSE.
Related reference:
v “db2_field_display_size - Returns the maximum number of bytes required to
display a column” on page 90
v “db2_field_num - Returns the position of the named column in a result set” on
page 92
v “db2_field_precision - Returns the precision of the indicated column in a result
set” on page 92
v “db2_field_scale - Returns the scale of the indicated column in a result set” on
page 93
v “db2_field_type - Returns the data type of the indicated column in a result set”
on page 94
v “db2_field_width - Returns the width of the current value of the indicated
column in a result set” on page 94
Description:
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns an integer containing the 0-indexed position of the named column in the
result set. If the specified column does not exist in the result set, db2_field_num()
returns FALSE.
Related reference:
v “db2_field_display_size - Returns the maximum number of bytes required to
display a column” on page 90
v “db2_field_name - Returns the name of the column in the result set” on page 91
v “db2_field_precision - Returns the precision of the indicated column in a result
set” on page 92
v “db2_field_scale - Returns the scale of the indicated column in a result set” on
page 93
v “db2_field_type - Returns the data type of the indicated column in a result set”
on page 94
v “db2_field_width - Returns the width of the current value of the indicated
column in a result set” on page 94
Description:
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns an integer containing the precision of the specified column. If the specified
column does not exist in the result set, db2_field_precision() returns FALSE.
Related reference:
v “db2_field_display_size - Returns the maximum number of bytes required to
display a column” on page 90
v “db2_field_name - Returns the name of the column in the result set” on page 91
v “db2_field_num - Returns the position of the named column in a result set” on
page 92
v “db2_field_scale - Returns the scale of the indicated column in a result set” on
page 93
v “db2_field_type - Returns the data type of the indicated column in a result set”
on page 94
v “db2_field_width - Returns the width of the current value of the indicated
column in a result set” on page 94
Description:
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns an integer containing the scale of the specified column. If the specified
column does not exist in the result set, db2_field_scale() returns FALSE.
Related reference:
Description:
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns a string containing the defined data type of the specified column. If the
specified column does not exist in the result set, db2_field_type() returns FALSE.
Description:
Returns the width of the current value of the indicated column in a result set. This
is the maximum width of the column for a fixed-length data type, or the actual
width of the column for a variable-length data type.
Parameters:
stmt
Specifies a statement resource containing a result set.
column
Specifies the column in the result set. This can either be an integer
representing the 0-indexed position of the column, or a string containing
the name of the column.
Return Values:
Returns an integer containing the width of the specified character or binary data
type column in a result set. If the specified column does not exist in the result set,
db2_field_width() returns FALSE.
Related reference:
v “db2_field_display_size - Returns the maximum number of bytes required to
display a column” on page 90
v “db2_field_name - Returns the name of the column in the result set” on page 91
v “db2_field_num - Returns the position of the named column in a result set” on
page 92
v “db2_field_precision - Returns the precision of the indicated column in a result
set” on page 92
v “db2_field_scale - Returns the scale of the indicated column in a result set” on
page 93
v “db2_field_type - Returns the data type of the indicated column in a result set”
on page 94
Description:
Returns the number of fields contained in a result set. This is most useful for
handling the result sets returned by dynamically generated queries, or for result
sets returned by stored procedures, where your application cannot otherwise know
how to retrieve and use the results.
Parameters:
stmt
A valid statement resource containing a result set.
Return Values:
Returns an integer value representing the number of fields in the result set
associated with the specified statement resource. Returns FALSE if the statement
resource is not a valid input value.
Examples:
The following example demonstrates how to retrieve the number of fields returned
in a result set.
<?php
$sql = "SELECT id, name, breed, weight FROM animals ORDER BY breed";
$stmt = db2_prepare($conn, $sql);
db2_execute($stmt, $sql);
$columns = db2_num_fields($stmt);
Related tasks:
v “Retrieving database metadata (ibm_db2)” on page 8
Related reference:
v “db2_field_display_size - Returns the maximum number of bytes required to
display a column” on page 90
v “db2_num_rows - Returns the number of rows affected by an SQL statement” on
page 96
v “db2_field_name - Returns the name of the column in the result set” on page 91
v “db2_field_num - Returns the position of the named column in a result set” on
page 92
v “db2_field_precision - Returns the precision of the indicated column in a result
set” on page 92
v “db2_field_scale - Returns the scale of the indicated column in a result set” on
page 93
v “db2_field_type - Returns the data type of the indicated column in a result set”
on page 94
v “db2_field_width - Returns the width of the current value of the indicated
column in a result set” on page 94
Description:
Parameters:
stmt
A valid stmt resource containing a result set.
Return Values:
Returns the number of rows affected by the last SQL statement issued by the
specified statement handle.
Related tasks:
v “Executing a single SQL statement in PHP (ibm_db2)” on page 11
v “Preparing and executing SQL statements in PHP (ibm_db2)” on page 12
Related reference:
v “db2_num_fields - Returns the number of fields contained in a result set” on
page 95
Description:
Parameters:
dsn
The Data Source Name, or DSN, contains the information required to
connect to the database.
In general, a DSN consists of the PDO driver name, followed by a colon,
followed by the PDO driver-specific connection syntax. To create a
cataloged connection to a DB2 database through the PDO_ODBC driver,
the DSN syntax is ″odbc:database-name″. For example, a DSN of
″odbc:SAMPLE″ connects to a cataloged DB2 database named SAMPLE
using the PDO_ODBC driver.
To create an uncataloged connection to a DB2 database, the DSN syntax is
as follows:
odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=hostname;PORT=port;
DATABASE=database;PROTOCOL=TCPIP;UID= USER;PWD=password;
Aliasing
dsn consists of a name name that maps to pdo.dsn.name in
php.ini defining the DSN string.
The alias must be defined in php.ini, and not .htaccess or
httpd.conf.
username
The user name for the DSN string. This parameter is optional if you have
specified the UID= clause in the dsn parameter.
password
The password for the DSN string. This parameter is optional if you have
specified the PWD= clause in the dsn parameter.
driver_options
An associative array of driver-specific connection options.
Return Values:
Exceptions:
Examples:
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo ’Connection failed: ’ . $e->getMessage();
}
?>
The following example assumes that the file /usr/local/dbconnect exists with file
permissions that enable PHP to read the file. The file contains the PDO DSN to
connect to a DB2 database through the PDO_ODBC driver:
odbc:DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=localhost;
PORT=50000;DATABASE=SAMPLE;PROTOCOL=TCPIP;UID=db2inst1;PWD=ibmdb2;
The PHP script can then create a database connection by simply passing the uri:
parameter and pointing to the file URI:
<?php
/* Connect to an ODBC database using driver invocation */
$dsn = ’uri:file:///usr/local/dbconnect’;
$user = ’’;
$password = ’’;
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo ’Connection failed: ’ . $e->getMessage();
}
?>
The following example assumes that php.ini contains the following entry to enable
a connection to a DB2 database cataloged as SAMPLE using only the alias MYDB:
[PDO]
pdo.dsn.MYDB="odbc:SAMPLE"
<?php
/* Connect to an ODBC database using an alias */
$dsn = ’mydb’;
$user = ’db2inst1’;
$password = ’ibmdb2’;
try {
$dbh = new PDO($dsn, $user, $password);
}catch (PDOException $e) {
echo ’Connection failed: ’ . $e->getMessage();
}
?>
bool PDO::beginTransaction()
Description:
Turns off autocommit mode. While autocommit mode is turned off, changes made
to the database via the PDO object instance are not committed until you end the
transaction by calling PDO::commit(). Calling PDO::rollback() will roll back all
changes to the database and return the connection to autocommit mode.
Examples:
The following example begins a transaction and issues two statements that modify
the database before rolling back the changes.
<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();
$dbh->rollBack();
bool PDO::commit()
Description:
Examples:
Commit a transaction:
<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();
int PDO::errorCode()
Description:
Fetches the SQLSTATE associated with the last operation on the database handle.
Return Values:
will not reflect that error. You must call PDOStatement::errorCode() to return the
error code for an operation performed on a particular statement handle.
Examples:
array PDO::errorInfo()
Description:
Return Values:
Element Information
0 SQLSTATE error code (a five-character
alphanumeric identifier defined in the ANSI
SQL standard).
1 Driver-specific error code.
2 Driver-specific error message.
Examples:
Description:
PDO::exec() does not return results from a SELECT statement. For a SELECT
statement that you only need to issue once during your program, consider issuing
PDO::query(). For a statement that you need to issue multiple times, prepare a
PDOStatement object with PDO::prepare() and issue the statement with
PDOStatement::execute().
Parameters:
statement
The SQL statement to prepare and execute.
Return Values:
PDO::exec() returns the number of rows that were modified or deleted by the SQL
statement you issued. If no rows were affected, PDO::exec() returns 0.
This function may return Boolean FALSE, but may also return a non-Boolean value
which evaluates to FALSE, such as 0 or ″″. Use the === operator for testing the
return value of this function.
Examples:
Description:
Note that some database and driver combinations may not support all of the
database connection attributes.
Parameters:
attribute
One of the PDO::ATTR_* constants. The constants that apply to database
connections are as follows: PDO::ATTR_AUTOCOMMIT
PDO::ATTR_CASE PDO::ATTR_CLIENT_VERSION
PDO::ATTR_CONNECTION_STATUS PDO::ATTR_DRIVER_NAME
PDO::ATTR_ERRMODE PDO::ATTR_ORACLE_NULLS
PDO::ATTR_PERSISTENT PDO::ATTR_PREFETCH
PDO::ATTR_SERVER_INFO PDO::ATTR_SERVER_VERSION
PDO::ATTR_TIMEOUT
Return Values:
A successful call returns the value of the requested PDO attribute. An unsuccessful
call returns null.
Examples:
array PDO::getAvailableDrivers()
Description:
This function returns a list of all PDO drivers which can be used to construct a
PDO object. This is a static method.
Return Values:
Examples:
A PDO::getAvailableDrivers example:
<?php
print_r(PDO::getAvailableDrivers());
?>
The preceding example returns the following output something similar to:
Array
(
[0] => odbc
)
Description:
Returns the ID of the last row that was inserted into the database using the same
PDO database connection.
Parameters:
sequence-name
Name of the sequence object from which the ID should be returned. If you
do not specify this parameter, PDO_ODBC returns the value of the identity
column for the last inserted row.
Return Values:
Description:
PDO supports named parameter markers in the PDO_ODBC driver for DB2 by
rewriting named parameters to question mark parameters.
Parameters:
statement
This must be a valid SQL statement for the target database management
system.
driver_options
This associative array sets attribute values for the PDOStatement object
that this method returns. You would most commonly use this to set the
PDO::ATTR_CURSOR value to PDO::CURSOR_SCROLL to request a
scrollable cursor.
Return Values:
Examples:
$red = $sth->fetchAll();
$sth->execute(array(’:calories’ => 175, ’:colour’ => ’yellow’));
$yellow = $sth->fetchAll();
?>
Description:
For a query that you need to issue multiple times, you will realize better
performance if you prepare a PDOStatement object using PDO::prepare() and issue
the statement with multiple calls to PDOStatement::execute().
If you do not fetch all of the data in a result set before issuing your next call to
PDO::query, your call may fail. Call PDOStatement::closeCursor() to release the
database resources associated with the PDOStatement object before issuing your
next call to PDO::query().
Parameters:
statement
The SQL statement to prepare and execute.
Return Values:
Examples:
Demonstrate PDO::query:
A nice feature of PDO::query() is that it enables you to iterate over the rowset
returned by a successfully executed SELECT statement.
<?php
function getFruit($conn) {
$sql = ’SELECT name, colour, calories FROM fruit ORDER BY name’;
foreach ($conn->query($sql) as $row) {
print $row[’NAME’] . "\t";
Description:
The PDO_ODBC driver for DB2 does not support this method. PDO::quote() is
intended to place quotes around the input string and escape any single quotes
within the input string.
If you are using this function to build SQL statements, you are strongly
recommended to use PDO::prepare() to prepare SQL statements with bound
parameters instead of using PDO::quote() to interpolate user input into a SQL
statement. Prepared statements with bound parameters are not only more portable,
more convenient, and vastly more secure, but are also much faster than
interpolating user input into slight variations on the same basic SQL statement.
Parameters:
string
The string to be quoted.
parameter_type
Provides a data type hint for drivers that have alternate quoting styles. The
default value is PDO::PARAM_STR.
Return Values:
Returns a quoted string that is theoretically safe to pass into an SQL statement.
Returns FALSE if the driver does not support quoting in this way.
Examples:
/* Simple string */
$string = ’Nice’;
print "Unquoted string: $string\n";
print "Quoted string: " . $conn->quote($string) . "\n";
?>
/* Dangerous string */
$string = ’Naughty \’ string’;
print "Unquoted string: $string\n";
print "Quoted string:" . $conn->quote($string) . "\n";
?>
/* Complex string */
$string = "Co’mpl’’ex \"st’\"ring";
print "Unquoted string: $string\n";
print "Quoted string: " . $conn->quote($string) . "\n";
?>
bool PDO::rollBack()
Description:
If the database was set to autocommit mode, this function will restore autocommit
mode after it has rolled back the transaction.
Examples:
The following example begins a transaction and issues two statements that modify
the database before rolling back the changes.
<?php
/* Begin a transaction, turning off autocommit */
$dbh->beginTransaction();
Description:
Sets an attribute on the database handle. The available generic attributes are listed
below.
PDO::ATTR_CASE: Forces column names to a specific case.
v PDO::CASE_LOWER: Force column names to lower case.
v PDO::CASE_NATURAL: Leave column names as returned by the
database driver.
v PDO::CASE_UPPER: Force column names to upper case.
PDO::ATTR_ERRMODE: Error reporting.
v PDO::ERRMODE_SILENT: Just set error codes.
v PDO::ERRMODE_WARNING: Raise E_WARNING level errors.
v PDO::ERRMODE_EXCEPTION: Throw exceptions.
PDO::ATTR_ORACLE_NULLS : Conversion of NULL and empty strings.
v PDO::NULL_NATURAL: No conversion.
v PDO::NULL_EMPTY_STRING: Empty string is converted to NULL.
v PDO::NULL_TO_STRING: NULL is converted to an empty string.
PDO::ATTR_STRINGIFY_FETCHES:
Convert numeric values to strings when fetching. Requires bool.
PDO::ATTR_STATEMENT_CLASS:
Set user-supplied statement class derived from PDOStatement. Cannot be
used with persistent PDO instances. Requires array(string classname,
array(mixed ctor_args)).
PDO::ATTR_AUTOCOMMIT:
Whether to autocommit every single statement.
Description:
Since information about the columns is not always available to PDO until the
statement is executed, portable applications should call this function after
PDO::execute().
Parameters:
column
Number of the column (1-indexed) or name of the column in the result set.
If using the column name, be aware that the name should match the case
of the column, as returned by the driver.
param
Name of the PHP variable to which the column will be bound.
type
Data type of the parameter, specified by the PDO::PARAM_* constants.
Examples:
Binding columns in the result set to PHP variables is an effective way to make the
data contained in each row immediately available to your application. The
following example demonstrates how PDO allows you to bind and retrieve
columns with a variety of options and with intelligent defaults.
<?php
function readData($dbh) {
$sql = ’SELECT name, colour, calories FROM fruit’;
try {
$stmt = $dbh->prepare($sql);
$stmt->execute();
Description:
Most parameters are input parameters, that is, parameters that are used in a
read-only fashion to build up the query. PDO_ODBC supports the invocation of
stored procedures that return data as output (OUT) parameters, as well as INOUT
parameters that both pass an input value to the database and are updated with an
output value after the CALL statement.
Parameters:
parameter
Parameter identifier. For a prepared statement using named placeholders,
this will be a parameter name of the form :name. For a prepared statement
using question mark placeholders, this will be the 1-indexed position of the
parameter.
variable
Name of the PHP variable to bind to the SQL statement parameter.
data_type
Explicit data type for the parameter using the PDO::PARAM_* constants. To
return an INOUT parameter from a stored procedure, use the bitwise OR
operator to set the PDO::PARAM_INPUT_OUTPUT bits for the data_type
parameter.
length
Length of the data type. To indicate that a parameter is an OUT parameter
from a stored procedure, you must explicitly set the length.
driver_options
Examples:
Description:
Parameters:
parameter
Parameter identifier. For a prepared statement using named placeholders,
this will be a parameter name of the form :name. For a prepared statement
using question mark placeholders, this will be the 1-indexed position of the
parameter.
value
Examples:
bool PDOStatement::closeCursor()
Description:
Examples:
A PDOStatement::closeCursor() example:
In the following example, the $stmt PDOStatement object returns multiple rows but
the application fetches only the first row, leaving the PDOStatement object
representing a result set with unfetched rows. To ensure that the application will
work with all databases and PDO drivers, the author inserts a call to
PDOStatement::closeCursor() on $stmt before executing the $otherStmt
PDOStatement object.
<?php
/* Create a PDOStatement object */
$stmt = $dbh->prepare(’SELECT foo FROM bar’);
int PDOStatement::columnCount()
Description:
If the PDOStatement object was returned from PDO::query(), the column count is
immediately available.
Return Values:
Returns the number of columns in the result set represented by the PDOStatement
object. If there is no result set, PDOStatement::columnCount() returns 0.
Examples:
Counting columns:
$sth->execute();
?>
int PDOStatement::errorCode()
Description:
Return Values:
Examples:
array PDOStatement::errorInfo()
Description:
Return Values:
Element Information
0 SQLSTATE error code (a five-character
alphanumeric identifier defined in the ANSI
SQL standard).
1 Driver-specific error code.
2 Driver-specific error message.
Examples:
echo "\nPDOStatement::errorInfo():\n";
$arr = $sth->errorInfo();
print_r($arr);
?>
Description:
Examples:
Description:
Fetches a row from a result set associated with a PDOStatement object. The
fetch_style parameter determines how PDO returns the row.
Parameters:
fetch_style
Controls how the next row will be returned to the caller. This value must
be one of the PDO::FETCH_* constants, defaulting to
PDO::FETCH_BOTH.
PDO::FETCH_ASSOC
returns an array indexed by column name as returned in your
result set
PDO::FETCH_BOTH (default)
returns an array indexed by both column name and 0-indexed
column number as returned in your result set
PDO::FETCH_BOUND
returns TRUE and assigns the values of the columns in your result
set to the PHP variables to which they were bound with the
PDOStatement::bindParam() method
PDO::FETCH_CLASS
returns a new instance of the requested class, mapping the
columns of the result set to named properties in the class
PDO::FETCH_INTO
updates an existing instance of the requested class, mapping the
columns of the result set to named properties in the class
PDO::FETCH_LAZY
combines PDO::FETCH_BOTH and PDO::FETCH_OBJ, creating
the object variable names as they are accessed
PDO::FETCH_NUM
returns an array indexed by column number as returned in your
result set, starting at column 0
PDO::FETCH_OBJ
returns an anonymous object with property names that correspond
to the column names returned in your result set
cursor_orientation
For a PDOStatement object representing a scrollable cursor, this value
determines which row will be returned to the caller. This value must be
one of the PDO::FETCH_ORI_* constants, defaulting to
PDO::FETCH_ORI_NEXT. To request a scrollable cursor for your
PDOStatement object, you must set the PDO::ATTR_CURSOR attribute to
PDO::CURSOR_SCROLL when you prepare the SQL statement with
PDO::prepare().
offset
For a PDOStatement object representing a scrollable cursor for which the
cursor_orientation parameter is set to PDO::FETCH_ORI_ABS, this value
specifies the absolute number of the row in the result set that shall be
fetched.
For a PDOStatement object representing a scrollable cursor for which the
cursor_orientation parameter is set to PDO::FETCH_ORI_REL, this value
specifies the row to fetch relative to the cursor position before
PDOStatement::fetch() was called.
Examples:
print("PDO::FETCH_BOTH: ");
print("Return next row as an array indexed by both column name and number\n");
$result = $sth->fetch(PDO::FETCH_BOTH);
print_r($result);
print("\n");
print("PDO::FETCH_LAZY: ");
print("Return next row as an anonymous object with column names as properties\n");
$result = $sth->fetch(PDO::FETCH_LAZY);
print_r($result);
print("\n");
print("PDO::FETCH_OBJ: ");
print("Return next row as an anonymous object with column names as properties\n");
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->NAME;
print("\n");
?>
PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number
Array
(
[NAME] => banana
[0] => banana
[COLOUR] => yellow
[1] => yellow
)
Reading backwards:
19 20 10
16 0 5
21 10 5
Description:
Parameters:
fetch_style
Controls the contents of the returned array as documented in
PDOStatement::fetch(). Defaults to PDO::FETCH_BOTH.
To return an array consisting of all values of a single column from the
result set, specify PDO::FETCH_COLUMN. You can specify which column
you want with the column-index parameter.
To fetch only the unique values of a single column from the result set,
bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_UNIQUE.
To return an associative array grouped by the values of a specified column,
bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_GROUP.
column_index
Returns the indicated 0-indexed column when the value of fetch_style is
PDO::FETCH_COLUMN. Defaults to 0.
Return Values:
Using this method to fetch large result sets will result in a heavy demand on
system and possibly network resources. Rather than retrieving all of the data and
manipulating it in PHP, consider using the database management system to
manipulate the result sets. For example, use the WHERE and SORT BY clauses in
SQL to restrict results before retrieving and processing them with PHP.
Examples:
The following example demonstrates how to return all of the values of a single
column from a result set, even though the SQL statement itself may return multiple
columns per row.
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
Array(3)
(
[0] =>
string(5) => apple
[1] =>
string(4) => pear
[2] =>
string(10) => watermelon
)
Description:
Parameters:
column_number
0-indexed number of the column you wish to retrieve from the row. If no
value is supplied, PDOStatement::fetchColumn() fetches the first column.
Return Values:
There is no way to return another column from the same row if you use
PDOStatement::fetchColumn() to retrieve data.
Examples:
/* Fetch the first column from the next row in the result set */
print("Fetch the first column from the next row in the result set:\n");
$result = $sth->fetchColumn();
print("name = $result\n");
print("Fetch the second column from the next row in the result set:\n");
$result = $sth->fetchColumn(1);
print("colour = $result\n");
?>
Description:
Gets an attribute of the statement. Currently, the only attribute that can be
retrieved is PDO::ATTR_CURSOR_NAME, which returns the name of the cursor
corresponding to this PDOStatement object.
Description:
Parameters:
column
The 0-indexed column in the result set.
Return Values:
Returns FALSE if the requested column does not exist in the result set, or if no
result set exists.
Examples:
The following example shows the results of retrieving the metadata for a single
column generated by a function (COUNT).
<?php
$select = $DB->query(’SELECT COUNT(*) FROM fruit’);
$meta = $select->getColumnMeta(0);
var_dump($meta);
?>
["name"]=>
string(8) "COUNT(*)"
["len"]=>
int(-1)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
bool PDOStatement::nextRowset()
Description:
Some database management systems, such as DB2, support stored procedures that
return more than one result set (also known as a result set).
PDOStatement::nextRowSet() enables you to access the second and subsequent
result sets associated with a PDOStatement object. Each result set can have a
different set of columns from the preceding result set.
Return Values:
Examples:
Result set 2:
orange orange 150
banana yellow 175
Result set 3:
lime green
apple red
banana yellow
int PDOStatement::rowCount()
Description:
If the last SQL statement executed by the associated PDOStatement was a SELECT
statement issued with a scrollable cursor, DB2 returns the number of rows returned
by that statement. However, scrollable cursors require more system resources on
the database management system and are not recommended for general usage.
Examples:
For most databases, PDOStatement::rowCount() does not return the number of rows
affected by a SELECT statement. Instead, use PDO::query() to issue a SELECT
COUNT(*) statement with the same predicates as your intended SELECT
/* Issue the real SELECT statement and work with the results */
$sql = "SELECT name FROM fruit WHERE calories > 100";
foreach ($conn->query($sql) as $row) {
print "Name: " . $row[’NAME’] . "\n";
}
}
/* No rows matched -- do something else */
else {
print "No rows matched the query.";
}
}
$res = null;
$conn = null;
?>
Description:
Sets an attribute on the statement. Currently, you can only set the
PDO::ATTR_CURSOR_NAME attribute to set the name of the cursor associated
with this PDOStatement object.
Description:
Parameters:
mode
The fetch mode must be one of the PDO::FETCH_* constants.
Return Values:
Examples:
Because Perl is an interpreted language and the Perl DBI Module uses dynamic
SQL, Perl is an ideal language for quickly creating and revising prototypes of DB2
applications. The Perl DBI Module uses an interface that is quite similar to the CLI
and JDBC interfaces, which makes it easy for you to port your Perl prototypes to
CLI and JDBC.
Most database vendors provide a database driver for the Perl DBI Module, which
means that you can also use Perl to create applications that access data from many
different database servers. For example, you can write a Perl DB2 application that
connects to an Oracle database using the DBD::Oracle database driver, fetch data
from the Oracle database, and insert the data into a DB2 database using the
DBD::DB2 database driver.
Related concepts:
v “Database Connections in Perl” on page 134
v “Example of a Perl Program” on page 136
Related tasks:
v “Building Perl applications” on page 136
Perl DBI
DB2 supports the Perl Database Interface (DBI) specification for data access
through the DBD::DB2 driver. The DB2 Perl DBI website is located at:
http://www.ibm.com/software/data/db2/perl/
Perl is an interpreted language and the Perl DBI Module uses dynamic SQL. These
properties make Perl an ideal language for quickly creating and revising DB2
applications. The Perl DBI Module uses an interface that is quite similar to the CLI
and JDBC interfaces, which makes it easy to port Perl applications to CLI and
JDBC, or to port CLI and JDBC applications to Perl.
Related concepts:
v “Programming Considerations for Perl” on page 133
The DBI module automatically loads the DBD::DB2 driver when you create a
database handle using the DBI->connect statement with the following syntax:
my $dbhandle = DBI->connect(‘dbi:DB2:dbalias’, $userID, $password);
where:
$dbhandle
represents the database handle returned by the connect statement
dbalias
represents a DB2 alias cataloged in your DB2 database directory
$userID
represents the user ID used to connect to the database
$password
represents the password for the user ID used to connect to the database
Procedure:
Related concepts:
The following Perl code creates a statement handle that accepts a parameter
marker for the WHERE clause of a SELECT statement. The code then executes the
statement twice using the input values 25000 and 35000 to replace the parameter
marker.
my $sth = $dbhandle->prepare(
’SELECT firstnme, lastname
FROM employee
WHERE salary > ?’
);
my $rc = $sth->execute(25000);
.
.
.
my $rc = $sth->execute(35000);
To return the SQLCODE associated with a Perl DBI database handle or statement
handle, call the err method. To return the message for an SQLCODE associated
with a Perl DBI database handle or statement handle, call the errstr method. For
example, to return the SQLCODE associated with the database handle $dbhandle,
include the following Perl statement in your application:
my $sqlcode = $dbhandle->err;
Perl Restrictions
The Perl DBI module supports only dynamic SQL. When you need to execute a
statement multiple times, you can improve the performance of your Perl DB2
applications by issuing a prepare call to prepare the statement.
For current information on the restrictions of the version of the DBD::DB2 driver
that you install on your workstation, refer to the CAVEATS file in the DBD::DB2
driver package.
Related concepts:
v “Programming Considerations for Perl” on page 133
my $database=’dbi:DB2:sample’;
my $user=’’;
my $password=’’;
my $sth = $dbh->prepare(
q{ SELECT firstnme, lastname
FROM employee }
)
or die "Can’t prepare statement: $DBI::errstr";
my $rc = $sth->execute
or die "Can’t execute statement: $DBI::errstr";
# check for problems which may have terminated the fetch early
warn $DBI::errstr if $DBI::err;
$sth->finish;
$dbh->disconnect;
Related concepts:
v “Programming Considerations for Perl” on page 133
Related tasks:
v “Building Perl applications” on page 136
Related reference:
v “Perl Samples” in Samples Topics
Procedure:
To run the perl interpreter on a DB2 Perl program on the command line, enter the
interpreter name and the program name (including extension):
Some programs require support files to be run. The tbsel sample program requires
several tables created by the tbselcreate.db2 CLP script. The tbselinit script
(UNIX), or the tbselinit.bat batch file (Windows), first calls tbseldrop.db2 to
drop the tables if they exist, and then calls tbselcreate.db2 to create them. So to
run the program, you would enter the following commands:
v If connecting locally on the server:
tbselinit
perl tbsel.pl
v If connecting from a remote client:
tbselinit
perl tbsel.pl sample <userid> <password>
Note: For a remote client, you need to modify the connect statement in the
tbselinit or tbselinit.bat file to hardcode your user ID and password:
db2 connect to sample user <userid> using <password>
Calling routines
DB2 client applications can access routines (stored procedures and user-defined
functions) that are created by supported host languages or by SQL procedures. For
example, the sample program spclient.pl can access the SQL procedures spserver
shared library, if it exists in the database.
Note: To build a host language routine, you must have the appropriate compiler
set up on the server. SQL procedures do not require a compiler. The shared
library can only be built on the server, and not from a remote client.
Next, come back to the perl samples directory (this can be on a remote client
machine), and run the Perl interpreter on the client program to access the spserver
shared library:
v If connecting locally on the server, enter the following command:
perl spclient
v If connecting from a remote client, enter the following command:
perl spclient sample <userid> <password>
Related concepts:
v “Perl DBI” on page 133
v “Programming Considerations for Perl” on page 133
Related reference:
v “Perl Samples” in Samples Topics
IBM periodically makes documentation updates available. If you access the online
version on the DB2 Information Center at ibm.com®, you do not need to install
documentation updates because this version is kept up-to-date by IBM. If you have
installed the DB2 Information Center, it is recommended that you install the
documentation updates. Documentation updates allow you to update the
information that you installed from the DB2 Information Center CD or downloaded
from Passport Advantage as new information becomes available.
Note: The DB2 Information Center topics are updated more frequently than either
the PDF or the hard-copy books. To get the most current information, install
the documentation updates as they become available, or refer to the DB2
Information Center at ibm.com.
You can access additional DB2 technical information such as technotes, white
papers, and Redbooks™ online at ibm.com. Access the DB2 Information
Management software library site at http://www.ibm.com/software/data/sw-
library/.
Documentation feedback
We value your feedback on the DB2 documentation. If you have suggestions for
how we can improve the DB2 documentation, send an e-mail to
[email protected]. The DB2 documentation team reads all of your feedback, but
cannot respond to you directly. Provide specific examples wherever possible so
that we can better understand your concerns. If you are providing feedback on a
specific topic or help file, include the topic title and URL.
Do not use this e-mail address to contact DB2 Customer Support. If you have a
DB2 technical issue that the documentation does not resolve, contact your local
IBM service center for assistance.
Related tasks:
v “Invoking command help from the command line processor” in Command
Reference
v “Invoking message help from the command line processor” in Command
Reference
v “Updating the DB2 Information Center installed on your computer or intranet
server” on page 147
Related reference:
v “DB2 technical library in hardcopy or PDF format” on page 142
Although the tables identify books available in print, the books might not be
available in your country or region.
The information in these books is fundamental to all DB2 users; you will find this
information useful whether you are a programmer, a database administrator, or
someone who works with DB2 Connect™ or other DB2 products.
Table 12. DB2 technical information
Name Form Number Available in print
Administration Guide: SC10-4221 Yes
Implementation
Administration Guide: Planning SC10-4223 Yes
Administrative API Reference SC10-4231 Yes
Administrative SQL Routines and SC10-4293 No
Views
Call Level Interface Guide and SC10-4224 Yes
Reference, Volume 1
Call Level Interface Guide and SC10-4225 Yes
Reference, Volume 2
Command Reference SC10-4226 No
Data Movement Utilities Guide SC10-4227 Yes
and Reference
Data Recovery and High SC10-4228 Yes
Availability Guide and Reference
Developing ADO.NET and OLE SC10-4230 Yes
DB Applications
Developing Embedded SQL SC10-4232 Yes
Applications
Note: The DB2 Release Notes provide additional information specific to your
product’s release and fix pack level. For more information, see the related
links.
Related concepts:
v “Overview of the DB2 technical information” on page 141
v “About the Release Notes” in Release Notes
Related tasks:
v “Ordering printed DB2 books” on page 144
Printed versions of many of the DB2 books available on the DB2 PDF
Documentation CD can be ordered for a fee from IBM. Depending on where you
are placing your order from, you may be able to order books online, from the IBM
Publications Center. If online ordering is not available in your country or region,
you can always order printed DB2 books from your local IBM representative. Note
that not all books on the DB2 PDF Documentation CD are available in print.
Procedure:
Related concepts:
v “Overview of the DB2 technical information” on page 141
Related reference:
v “DB2 technical library in hardcopy or PDF format” on page 142
Procedure:
To invoke SQL state help, open the command line processor and enter:
? sqlstate or ? class code
where sqlstate represents a valid five-digit SQL state and class code represents the
first two digits of the SQL state.
For example, ? 08003 displays help for the 08003 SQL state, and ? 08 displays help
for the 08 class code.
Related tasks:
v “Invoking command help from the command line processor” in Command
Reference
v “Invoking message help from the command line processor” in Command
Reference
For DB2 Version 8 topics, go to the Version 8 Information Center URL at:
http://publib.boulder.ibm.com/infocenter/db2luw/v8/.
Related tasks:
v “Setting up access to DB2 contextual help and documentation” in Administration
Guide: Implementation
Procedure:
Note: Adding a language does not guarantee that the computer has the fonts
required to display the topics in the preferred language.
v To move a language to the top of the list, select the language and click the
Move Up button until the language is first in the list of languages.
3. Clear the browser cache and then refresh the page to display the DB2
Information Center in your preferred language.
On some browser and operating system combinations, you might have to also
change the regional settings of your operating system to the locale and language of
your choice.
To determine if there is an update available for the entire DB2 Information Center,
look for the 'Last updated' value on the Information Center home page. Compare
the value in your locally installed home page to the date of the most recent
downloadable update at http://www.ibm.com/software/data/db2/udb/support/
icupdate.html. You can then update your locally-installed Information Center if a
more recent downloadable update is available.
Note: Updates are also available on CD. For details on how to configure your
Information Center to install updates from CD, see the related links.
If update packages are available, use the Update feature to download the
packages. (The Update feature is only available in stand-alone mode.)
3. Stop the stand-alone Information Center, and restart the DB2 Information
Center service on your computer.
Procedure:
Note: The help_end batch file contains the commands required to safely
terminate the processes that were started with the help_start batch file.
Do not use Ctrl-C or any other method to terminate help_start.bat.
v On Linux, run the help_end script using the fully qualified path for the DB2
Information Center:
<DB2 Information Center dir>/doc/bin/help_end
Related concepts:
v “DB2 Information Center installation options” in Quick Beginnings for DB2 Servers
Related tasks:
v “Installing the DB2 Information Center using the DB2 Setup wizard (Linux)” in
Quick Beginnings for DB2 Servers
v “Installing the DB2 Information Center using the DB2 Setup wizard (Windows)”
in Quick Beginnings for DB2 Servers
You can view the XHTML version of the tutorial from the Information Center at
http://publib.boulder.ibm.com/infocenter/db2help/.
Some lessons use sample data or code. See the tutorial for a description of any
prerequisites for its specific tasks.
DB2 tutorials:
Related concepts:
v “Visual Explain overview” in Administration Guide: Implementation
Related concepts:
v “Introduction to problem determination” in Troubleshooting Guide
v “Overview of the DB2 technical information” on page 141
Personal use: You may reproduce these Publications for your personal, non
commercial use provided that all proprietary notices are preserved. You may not
distribute, display or make derivative work of these Publications, or any portion
thereof, without the express consent of IBM.
Commercial use: You may reproduce, distribute and display these Publications
solely within your enterprise provided that all proprietary notices are preserved.
You may not make derivative works of these Publications, or reproduce, distribute
or display these Publications or any portion thereof outside your enterprise,
without the express consent of IBM.
IBM reserves the right to withdraw the permissions granted herein whenever, in its
discretion, the use of the Publications is detrimental to its interest or, as
determined by IBM, the above instructions are not being properly followed.
You may not download, export or re-export this information except in full
compliance with all applicable laws and regulations, including all United States
export laws and regulations.
IBM may have patents or pending patent applications covering subject matter
described in this document. The furnishing of this document does not give you
any license to these patents. You can send license inquiries, in writing, to:
IBM Director of Licensing
IBM Corporation
North Castle Drive
Armonk, NY 10504-1785
U.S.A.
For license inquiries regarding double-byte (DBCS) information, contact the IBM
Intellectual Property Department in your country/region or send inquiries, in
writing, to:
IBM World Trade Asia Corporation
Licensing
2-31 Roppongi 3-chome, Minato-ku
Tokyo 106, Japan
The following paragraph does not apply to the United Kingdom or any other
country/region where such provisions are inconsistent with local law:
INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS
PUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS
FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or
implied warranties in certain transactions; therefore, this statement may not apply
to you.
Any references in this information to non-IBM Web sites are provided for
convenience only and do not in any manner serve as an endorsement of those Web
sites. The materials at those Web sites are not part of the materials for this IBM
product, and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it
believes appropriate without incurring any obligation to you.
The licensed program described in this document and all licensed material
available for it are provided by IBM under terms of the IBM Customer Agreement,
IBM International Program License Agreement, or any equivalent agreement
between us.
All statements regarding IBM’s future direction or intent are subject to change or
withdrawal without notice, and represent goals and objectives only.
This information may contain examples of data and reports used in daily business
operations. To illustrate them as completely as possible, the examples include the
names of individuals, companies, brands, and products. All of these names are
fictitious, and any similarity to the names and addresses used by an actual
business enterprise is entirely coincidental.
COPYRIGHT LICENSE:
Each copy or any portion of these sample programs or any derivative work must
include a copyright notice as follows:
Trademarks
Company, product, or service names identified in the documents of the DB2
Version 9 documentation library may be trademarks or service marks of
International Business Machines Corporation or other companies. Information on
the trademarks of IBM Corporation in the United States, other countries, or both is
located at http://www.ibm.com/legal/copytrade.shtml.
Microsoft®, Windows, Windows NT®, and the Windows logo are trademarks of
Microsoft Corporation in the United States, other countries, or both.
Intel®, Itanium®, Pentium®, and Xeon® are trademarks of Intel Corporation in the
United States, other countries, or both.
Java™ and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in
the United States, other countries, or both.
UNIX is a registered trademark of The Open Group in the United States and other
countries.
R
E retrieving data
Perl 134
error handling
Perl 135
examples
Perl program 136 S
SQL statements
displaying help 145
H static SQL
Perl, unsupported 135
help
displaying 146
for SQL statements 145
host variables T
unsupported in Perl 134 terms and conditions
use of publications 150
troubleshooting
I online information 149
tutorials 149
Information Center
tutorials
updating 147
troubleshooting and problem
versions 146
determination 149
viewing in different languages 146
Visual Explain 149
N U
notices 151
updates
DB2 Information Center 147
Information Center 147
Printed in USA
SC10-4234-00