略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: oci_new_collection

2024-04-20

oci_new_collection

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

oci_new_collection分配新的 collection 对象

说明

oci_new_collection(resource $connection, string $tdo, string $schema = ?): OCI-Collection

分配一个新的 collection 对象。tdo 参数应为一个有效的名字类型(大写)。第三个可选参数 schema 应指向建立名字对象的架构。oci_new_collection() 使用当前用户作为 schema 的默认值。

oci_new_collection() 如果出错返回 false

注意:

在 PHP 5.0.0 之前的版本必须使用 ocinewcollection() 替代本函数。该函数名仍然可用,为向下兼容作为 oci_new_collection() 的别名。不过其已被废弃,不推荐使用。

add a noteadd a note

User Contributed Notes 1 note

up
3
VLroyrenn
4 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

官方地址:https://www.php.net/manual/en/function.oci-new-collection.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3