-
Notifications
You must be signed in to change notification settings - Fork 788
/
Copy pathdb2-connect.xml
712 lines (689 loc) · 23.1 KB
/
db2-connect.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- Generated by xml_proto.php v2.2. Found in /scripts directory of phpdoc. -->
<refentry xml:id="function.db2-connect" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>db2_connect</refname>
<refpurpose>
Returns a connection to a database
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>resource</type><type>false</type></type><methodname>db2_connect</methodname>
<methodparam><type>string</type><parameter>database</parameter></methodparam>
<methodparam><type class="union"><type>string</type><type>null</type></type><parameter>username</parameter></methodparam>
<methodparam><type class="union"><type>string</type><type>null</type></type><parameter>password</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>[]</initializer></methodparam>
</methodsynopsis>
<para>
Creates a new connection to an IBM DB2 Universal Database, IBM Cloudscape,
or Apache Derby database.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>
For a cataloged connection to a database, <parameter>database</parameter>
represents the database alias in the DB2 client catalog.
</para>
<para>
For an uncataloged connection to a database,
<parameter>database</parameter> represents a complete connection
string in the following format:
<literallayout>DATABASE=<parameter>database</parameter>;HOSTNAME=<parameter>hostname</parameter>;PORT=<parameter>port</parameter>;PROTOCOL=TCPIP;UID=<parameter>username</parameter>;PWD=<parameter>password</parameter>;</literallayout>
<note>
<para>
When connecting to Db2 on IBM i, the underlying system calls
<link xlink:href="&url.db2.sqldriverconnect;">SQLDriverConnect</link>,
which only accepts DSN, UID, and PWD for the
<link xlink:href="&url.db2.connection.string;">connection string</link>.
Like so:
<literallayout>DSN=<parameter>database</parameter>;UID=<parameter>username</parameter>;PWD=<parameter>password</parameter>;</literallayout>
</para>
</note>
where the parameters represent the following values:
<variablelist>
<varlistentry>
<term><parameter>database</parameter></term>
<listitem>
<para>
The name of the database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>hostname</parameter></term>
<listitem>
<para>
The hostname or IP address of the database server.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>port</parameter></term>
<listitem>
<para>
The TCP/IP port on which the database is listening for
requests.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>username</parameter></term>
<listitem>
<para>
The username with which you are connecting to the
database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>password</parameter></term>
<listitem>
<para>
The password with which you are connecting to the database.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>username</parameter></term>
<listitem>
<para>
The username with which you are connecting to the database.
</para>
<para>
For uncataloged connections, you must pass a &null; value or empty
string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>password</parameter></term>
<listitem>
<para>
The password with which you are connecting to the database.
</para>
<para>
For uncataloged connections, you must pass a &null; value or empty
string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>options</parameter></term>
<listitem>
<para>
An associative array of connection options that affect the behavior
of the connection, where valid array keys include:
<variablelist>
<varlistentry>
<term><parameter>autocommit</parameter></term>
<listitem>
<para>
Passing the <constant>DB2_AUTOCOMMIT_ON</constant> value turns
autocommit on for this connection handle.
</para>
<para>
Passing the <constant>DB2_AUTOCOMMIT_OFF</constant> value turns
autocommit off for this connection handle.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>DB2_ATTR_CASE</parameter></term>
<listitem>
<para>
Passing the <constant>DB2_CASE_NATURAL</constant> value specifies
that column names are returned in natural case.
</para>
<para>
Passing the <constant>DB2_CASE_LOWER</constant> value specifies
that column names are returned in lower case.
</para>
<para>
Passing the <constant>DB2_CASE_UPPER</constant> value specifies
that column names are returned in upper case.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>CURSOR</parameter></term>
<listitem>
<para>
Passing the <constant>DB2_FORWARD_ONLY</constant> value specifies a
forward-only cursor for a statement resource. This is the default
cursor type and is supported on all database servers.
</para>
<para>
Passing the <constant>DB2_SCROLLABLE</constant> 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.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The following new option is available in ibm_db2 version 1.7.0 and later.
<variablelist>
<varlistentry>
<term><parameter>trustedcontext</parameter></term>
<listitem>
<para>
Passing the DB2_TRUSTED_CONTEXT_ENABLE value turns trusted context
on for this connection handle. This parameter cannot be set using
<function>db2_set_option</function>.
</para>
<para>
This key works only if the database is cataloged (even if the
database is local), or if you specify the full DSN when you create
the connection.
</para>
<para>
To catalog the database, use following commands:
</para>
<para>
<literallayout>db2 catalog tcpip node loopback remote <SERVERNAME> server <SERVICENAME>
db2 catalog database <LOCALDBNAME> as <REMOTEDBNAME> at node loopback
db2 "update dbm cfg using svcename <SERVICENAME>"
db2set DB2COMM=TCPIP</literallayout>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The following new i5/OS options are available in ibm_db2 version 1.5.1
and later.
<variablelist>
<varlistentry>
<term><parameter>i5_lib</parameter></term>
<listitem>
<para>
A character value that indicates the default library that will be
used for resolving unqualified file references. This is not valid
if the connection is using system naming mode.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_naming</parameter></term>
<listitem>
<para>
<literal>DB2_I5_NAMING_ON</literal> value turns on DB2 UDB CLI iSeries
system naming mode. Files are qualified using the slash (/) delimiter.
Unqualified files are resolved using the library list for the job.
</para>
<para>
<literal>DB2_I5_NAMING_OFF</literal> value turns off DB2 UDB CLI default
naming mode, which is SQL naming. Files are qualified using the period (.)
delimiter. Unqualified files are resolved using either the default library
or the current user ID.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_commit</parameter></term>
<listitem>
<para>
The <parameter>i5_commit</parameter> attribute should be set before the
<function>db2_connect</function>. If the value is changed after the
connection has been established, and the connection is to a remote data
source, the change does not take effect until the next successful
<function>db2_connect</function> for the connection handle.
<note>
<para>
The php.ini setting <parameter>ibm_db2.i5_allow_commit</parameter>==0
or <literal>DB2_I5_TXN_NO_COMMIT</literal> is the default, but may be
overridden with the <parameter>i5_commit</parameter> option.
</para>
</note>
</para>
<para>
<literal>DB2_I5_TXN_NO_COMMIT</literal> - Commitment control is not used.
</para>
<para>
<literal>DB2_I5_TXN_READ_UNCOMMITTED</literal> - Dirty reads, nonrepeatable
reads, and phantoms are possible.
</para>
<para>
<literal>DB2_I5_TXN_READ_COMMITTED</literal> - Dirty reads are not possible.
Nonrepeatable reads, and phantoms are possible.
</para>
<para>
<literal>DB2_I5_TXN_REPEATABLE_READ</literal> - Dirty reads and nonrepeatable
reads are not possible. Phantoms are possible.
</para>
<para>
<literal>DB2_I5_TXN_SERIALIZABLE</literal> - Transactions are serializable.
Dirty reads, non-repeatable reads, and phantoms are not possible
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_query_optimize</parameter></term>
<listitem>
<para>
<literal>DB2_FIRST_IO</literal> All queries are optimized with the goal of
returning the first page of output as fast as possible. This goal works well
when the output is controlled by a user who is most likely to cancel the query
after viewing the first page of output data. Queries coded with an
OPTIMIZE FOR nnn ROWS clause honor the goal specified by the clause.
</para>
<para>
<literal>DB2_ALL_IO</literal> All queries are optimized with the goal of running
the entire query to completion in the shortest amount of elapsed time. This is a
good option when the output of a query is being written to a file or report, or
the interface is queuing the output data. Queries coded with an OPTIMIZE FOR nnn
ROWS clause honor the goal specified by the clause. This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_dbcs_alloc</parameter></term>
<listitem>
<para>
<literal>DB2_I5_DBCS_ALLOC_ON</literal> value turns on DB2 6X allocation scheme
for DBCS translation column size growth.
</para>
<para>
<literal>DB2_I5_DBCS_ALLOC_OFF</literal> value turns off DB2 6X allocation scheme
for DBCS translation column size growth.
</para>
<para>
Note: php.ini setting <parameter>ibm_db2.i5_dbcs_alloc</parameter>==0 or
<literal>DB2_I5_DBCS_ALLOC_OFF</literal> is the default, but may be overridden
with the <parameter>i5_dbcs_alloc</parameter> option.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_date_fmt</parameter></term>
<listitem>
<para>
<literal>DB2_I5_FMT_ISO</literal> - The International Organization for Standardization
(ISO) date format yyyy-mm-dd is used. This is the default.
</para>
<para>
<literal>DB2_I5_FMT_USA</literal> - The United States date format mm/dd/yyyy is used.
</para>
<para>
<literal>DB2_I5_FMT_EUR</literal> - The European date format dd.mm.yyyy is used.
</para>
<para>
<literal>DB2_I5_FMT_JIS</literal> - The Japanese Industrial Standard date format
yyyy-mm-dd is used.
</para>
<para>
<literal>DB2_I5_FMT_MDY</literal> - The date format mm/dd/yyyy is used.
</para>
<para>
<literal>DB2_I5_FMT_DMY</literal> - The date format dd/mm/yyyy is used.
</para>
<para>
<literal>DB2_I5_FMT_YMD</literal> - The date format yy/mm/dd is used.
</para>
<para>
<literal>DB2_I5_FMT_JUL</literal> - The Julian date format yy/ddd is used.
</para>
<para>
<literal>DB2_I5_FMT_JOB</literal> - The job default is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_date_sep</parameter></term>
<listitem>
<para>
<literal>DB2_I5_SEP_SLASH</literal> - A slash ( / ) is used as the date separator.
This is the default.
</para>
<para>
<literal>DB2_I5_SEP_DASH</literal> - A dash ( - ) is used as the date separator.
</para>
<para>
<literal>DB2_I5_SEP_PERIOD</literal> - A period ( . ) is used as the date
separator.
</para>
<para>
<literal>DB2_I5_SEP_COMMA</literal> - A comma ( , ) is used as the date separator.
</para>
<para>
<literal>DB2_I5_SEP_BLANK</literal> - A blank is used as the date separator.
</para>
<para>
<literal>DB2_I5_SEP_JOB</literal> - The job default is used
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_time_fmt</parameter></term>
<listitem>
<para>
<literal>DB2_I5_FMT_ISO</literal> - The International Organization for
Standardization (ISO) time format hh.mm.ss is used. This is the default.
</para>
<para>
<literal>DB2_I5_FMT_USA</literal> - The United States time format
hh:mmxx is used, where xx is AM or PM.
</para>
<para>
<literal>DB2_I5_FMT_EUR</literal> - The European time format hh.mm.ss
is used.
</para>
<para>
<literal>DB2_I5_FMT_JIS</literal> - The Japanese Industrial Standard
time format hh:mm:ss is used.
</para>
<para>
<literal>DB2_I5_FMT_HMS</literal> - The hh:mm:ss format is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_time_sep</parameter></term>
<listitem>
<para>
<literal>DB2_I5_SEP_COLON</literal> - A colon ( : ) is used as the time
separator. This is the default.
</para>
<para>
<literal>DB2_I5_SEP_PERIOD</literal> - A period ( . ) is used as the time
separator.
</para>
<para>
<literal>DB2_I5_SEP_COMMA</literal> - A comma ( , ) is used as the time
separator.
</para>
<para>
<literal>DB2_I5_SEP_BLANK</literal> - A blank is used as the time separator.
</para>
<para>
<literal>DB2_I5_SEP_JOB</literal> - The job default is used.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>i5_decimal_sep</parameter></term>
<listitem>
<para>
<literal>DB2_I5_SEP_PERIOD</literal> - A period ( . ) is used as
the decimal separator. This is the default.
</para>
<para>
<literal>DB2_I5_SEP_COMMA</literal> - A comma ( , ) is used as the
decimal separator.
</para>
<para>
<literal>DB2_I5_SEP_JOB</literal> - The job default is used.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The following new i5/OS option is available in ibm_db2 version 1.8.0
and later.
<variablelist>
<varlistentry>
<term><parameter>i5_libl</parameter></term>
<listitem>
<para>
A character value that indicates the library list that will be used for
resolving unqualified file references. Specify the library list
elements separated by blanks 'i5_libl'=>"MYLIB YOURLIB ANYLIB".
</para>
<note>
<para>
<parameter>i5_libl</parameter> calls qsys2/qcmdexc('cmd',cmdlen), which is only
available in i5/OS V5R4 and later.
</para>
</note>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a connection handle resource if the connection attempt is
successful. If the connection attempt fails, <function>db2_connect</function>
returns &false;.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Creating a cataloged connection</title>
<para>
Cataloged connections require you to have previously cataloged the target
database through the DB2 Command Line Processor (CLP) or DB2
Configuration Assistant.
</para>
<programlisting role="php">
<![CDATA[
<?php
$database = 'SAMPLE';
$user = 'db2inst1';
$password = 'ibmdb2';
$conn = db2_connect($database, $user, $password);
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Connection succeeded.
]]>
</screen>
</example>
<example>
<title>Creating an uncataloged connection</title>
<para>
An uncataloged connection enables you to dynamically connect to a
database.
</para>
<programlisting role="php">
<![CDATA[
<?php
$database = 'SAMPLE';
$user = 'db2inst1';
$password = 'ibmdb2';
$hostname = 'localhost';
$port = 50000;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Connection succeeded.
]]>
</screen>
</example>
<example>
<title>Creating a connection with autocommit off by default</title>
<para>
Passing an array of options to <function>db2_connect</function> enables
you to modify the default behavior of the connection handle.
</para>
<programlisting role="php">
<![CDATA[
<?php
$database = 'SAMPLE';
$user = 'db2inst1';
$password = 'ibmdb2';
$options = array('autocommit' => DB2_AUTOCOMMIT_OFF);
$conn = db2_connect($database, $user, $password, $options);
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.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Connection succeeded.
Autocommit is off.
]]>
</screen>
</example>
<example>
<title>i5/OS best performance</title>
<para>
To achieve best performance for your i5/OS ibm_db2 1.5.1 PHP application
use the default host, userid, and password for your
<function>db2_connect</function>.
</para>
<programlisting role="php">
<![CDATA[
<?php
$library = "ADC";
$i5 = db2_connect("", "", "", array("i5_lib"=>"qsys2"));
$result = db2_exec($i5,
"select * from systables where table_schema = '$library'");
while ($row = db2_fetch_both($result)) {
echo $row['TABLE_NAME']."</br>";
}
db2_close($i5);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
ANIMALS
NAMES
PICTURES
]]>
</screen>
</example>
<example>
<title>Using trusted context</title>
<para>
The following example shows how to enable trusted context, switch
users, and get the current user ID.
</para>
<programlisting role="php">
<![CDATA[
<?php
$database = "SAMPLE";
$hostname = "localhost";
$port = 50000;
$authID = "db2inst1";
$auth_pass = "ibmdb2";
$tc_user = "tcuser";
$tc_pass = "tcpassword";
$dsn = "DATABASE=$database;HOSTNAME=$hostname;PORT=$port;
PROTOCOL=TCPIP;UID=$authID;PWD=$auth_pass;";
$options = array ("trustedcontext" => DB2_TRUSTED_CONTEXT_ENABLE);
$tc_conn = db2_connect($dsn, "", "", $options);
if($tc_conn) {
echo "Explicit trusted connection succeeded.\n";
if(db2_get_option($tc_conn, "trustedcontext")) {
$userBefore = db2_get_option($tc_conn, "trusted_user");
//Do some work as user 1.
//Switching to trusted user.
$parameters = array("trusted_user" => $tc_user,
"trusted_password" => $tcuser_pass);
$res = db2_set_option ($tc_conn, $parameters, 1);
$userAfter = db2_get_option($tc_conn, "trusted_user");
//Do more work as trusted user.
if($userBefore != $userAfter) {
echo "User has been switched." . "\n";
}
}
db2_close($tc_conn);
}
else {
echo "Explicit trusted connection failed.\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Explicit trusted connection succeeded.
User has been switched.
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>db2_close</function></member>
<member><function>db2_pconnect</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->