db2_pconnect
(PECL ibm_db2:1.0-1.6.2)
db2_pconnect — Returns a persistent connection to a database
Описание
Returns a persistent connection to an IBM DB2 Universal Database, IBM Cloudscape, or Apache Derby database. For more information on persistent connections, refer to Постоянные соединения с базами данных.
Calling db2_close() on a persistent connection always returns TRUE, but the underlying DB2 client connection remains open and waiting to serve the next matching db2_pconnect() request.
Список параметров
- 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.
- DB2_ATTR_CASE
-
Passing the DB2_CASE_NATURAL value specifies that column names are returned in natural case.
Passing the DB2_CASE_LOWER value specifies that column names are returned in lower case.
Passing the DB2_CASE_UPPER value specifies that column names are returned in upper case.
- CURSOR
-
Passing the DB2_FORWARD_ONLY value specifies a forward-only cursor for a statement resource. This is the default cursor type and is supported on all database servers.
Passing the DB2_SCROLLABLE value specifies a scrollable cursor for a statement resource. This mode enables random access to rows in a result set, but currently is supported only by IBM DB2 Universal Database.
-
Возвращаемые значения
Returns a connection handle resource if the connection attempt is successful. db2_pconnect() tries to reuse an existing connection resource that exactly matches the database , username , and password parameters. If the connection attempt fails, db2_pconnect() returns FALSE.
Примеры
Пример #1 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';
$pconn = db2_pconnect($database, $user, $password);
if ($pconn) {
echo "Persistent connection succeeded.";
}
else {
echo "Persistent connection failed.";
}
$pconn2 = db2_pconnect($database, $user, $password);
if ($pconn) {
echo "Second persistent connection succeeded.";
}
else {
echo "Second persistent connection failed.";
}
?>
Результат выполнения данного примера:
Persistent connection succeeded. Second persistent connection succeeded.
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- IBM DB2, Cloudscape and Apache Derby
- db2_autocommit
- db2_bind_param
- db2_client_info
- db2_close
- db2_column_privileges
- db2_columns
- db2_commit
- db2_conn_error
- db2_conn_errormsg
- db2_connect
- db2_cursor_type
- db2_escape_string
- db2_exec
- db2_execute
- db2_fetch_array
- db2_fetch_assoc
- db2_fetch_both
- db2_fetch_object
- db2_fetch_row
- db2_field_display_size
- db2_field_name
- db2_field_num
- db2_field_precision
- db2_field_scale
- db2_field_type
- db2_field_width
- db2_foreign_keys
- db2_free_result
- db2_free_stmt
- db2_get_option
- db2_last_insert_id
- db2_lob_read
- db2_next_result
- db2_num_fields
- db2_num_rows
- db2_pclose
- db2_pconnect
- db2_prepare
- db2_primary_keys
- db2_procedure_columns
- db2_procedures
- db2_result
- db2_rollback
- db2_server_info
- db2_set_option
- db2_special_columns
- db2_statistics
- db2_stmt_error
- db2_stmt_errormsg
- db2_table_privileges
- db2_tables
Коментарии
If You will create db2 connection on IBMi , QSQSRVR job will be created under QSYSWRK subsystem with specified user.
You can ensure it with using db2_pconnect() function.
For example, db2_pconnect('*LOCAL', 'TESTUSR', 'PASSWORD') will bring us QSQSRVR job with TESTUSR user.
If You omit the user, IHS default user is used in the job.
The ibm_db2.ini file controls many properties related to to pconnect. For example, stale connection handling is configurable.