CakeFest 2024: The Official CakePHP Conference

oci_new_collection

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

oci_new_collectionAsigna un nuevo objeto colección

Descripción

oci_new_collection(resource $connection, string $type_name, ?string $schema = null): OCICollection|false

Asigna un nuevo objeto colección.

Parámetros

connection

Un identificador de conexión de Oracle devuelto por oci_connect() o oci_pconnect().

tdo

Debería ser un tipo con nombre válido (en mayúsculas).

schema

Debería apuntar al esquema donde fue creado el tipo con nombre. El nombre del usuario actual es usado cuando el valor null es pasado.

Valores devueltos

Devuelve un nuevo objeto OCICollection o false en caso de error.

Historial de cambios

Versión Descripción
8.0.0, PECL OCI8 3.0.0 schema es ahora nullable.

Notas

Nota:

La clase OCICollection se llamó OCI-Collection antes de PHP 8 y OCI8 3.0.0.

Nota:

En versiones de PHP anteriores a la 5.0.0 se debe usar ocinewcollection() en su lugar. Este nombre aún puede usarse; se dejó como alias de oci_new_collection() por razones de retrocompatibilidad. Sin embargo, este nombre es obsoleto y no se recomienda.

add a note

User Contributed Notes 1 note

up
1
VLroyrenn
6 years 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