PHP 7.1.21 Released

oci_new_collection

(PHP 5, PHP 7, PECL OCI8 >= 1.1.0)

oci_new_collection新しいコレクションオブジェクトを割り当てる

説明

OCI-Collection oci_new_collection ( resource $connection , string $tdo [, string $schema = NULL ] )

新しいコレクションオブジェクトを割り当てます。

パラメータ

connection

oci_connect() あるいは oci_pconnect() が返す Oracle 接続 ID。

tdo

有効な型名 (大文字)。

schema

型を作成したスキーマを指定しなければなりません。 現在のユーザー名がデフォルト値となります。

返り値

新しい OCICollection オブジェクト、 あるいはエラー時に FALSE を返します。

注意

注意:

PHP バージョン 5.0.0 以前では、代わりに ocinewcollection() を使用しなければなりません。 まだこの名前を使用することができ、下位互換性のため oci_new_collection() への別名として残されていますが、 推奨されません。

add a note add a note

User Contributed Notes 1 note

up
1
VLroyrenn
4 months ago
This is a woefully underdocumented feature (at least here), but being able to bind collections to prepared statements instead of rolling your own SQL arrays is a massive improvement in terms of safety and conveinience, and a feature I think more DBMS should have in their API.

You can basically send collections of the types listed by the following query :

SELECT * FROM SYS.ALL_TYPES WHERE TYPECODE = 'COLLECTION' AND TYPE_NAME LIKE 'ODCI%'

Those are all collections that can contain any number of the SQL type indicated in their name.

<?php
$my_array
= ["foo", "bar", "baz"];

$my_collection = oci_new_collection($conn, 'ODCIVARCHAR2LIST', 'SYS');

foreach(
$my_array as $elem) {
   
$cell_collection->append($elem);
}

oci_bind_by_name($statement, ":collection", $my_collection, -1, SQLT_NTY);
?>

The collection ressource can be appended with numbers, strings or dates (which need to be passed as strings in the "DD-MON-YY" format, such as "27-MAR-18", apparently) depending on the types supported by the collection you're using, and none of these appear to support timestamps or any of the more complex data types.

Code for the OCI collection type, for reference :

http://git.php.net/?p=php-src.git;a=blob;f=ext/oci8/oci8_collection.c;hb=refs/heads/master#l429
To Top